0
0
Pythonprogramming~10 mins

Random data generation in Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the module needed for random data generation.

Python
import [1]
Drag options to blanks, or click blank then click option'
Arandom
Bsys
Cmath
Dos
Attempts:
3 left
💡 Hint
Common Mistakes
Importing unrelated modules like sys or math instead of random.
2fill in blank
medium

Complete the code to generate a random integer between 1 and 10.

Python
num = random.[1](1, 10)
Drag options to blanks, or click blank then click option'
Arandom
Brandint
Crandrange
Dchoice
Attempts:
3 left
💡 Hint
Common Mistakes
Using random.choice which selects from a sequence, not a range of integers.
3fill in blank
hard

Fix the error in the code to select a random element from the list.

Python
item = random.[1](items)
Drag options to blanks, or click blank then click option'
Arandint
Brandrange
Cchoice
Dsample
Attempts:
3 left
💡 Hint
Common Mistakes
Using randint which returns an integer, not an element from a list.
4fill in blank
hard

Fill both blanks to create a list of 5 random integers between 1 and 20.

Python
numbers = [random.[1](1, 20) for [2] in range(5)]
Drag options to blanks, or click blank then click option'
Arandint
Bi
Cj
Drandrange
Attempts:
3 left
💡 Hint
Common Mistakes
Using randrange which excludes the upper bound, or confusing loop variable names.
5fill in blank
hard

Fill all three blanks to create a dictionary with words as keys and their lengths as values, only for words longer than 3 letters.

Python
lengths = {word: [1] for word in words if len(word) [2] 3 and word.[3]('a')}
Drag options to blanks, or click blank then click option'
Alen(word)
B>
Cstartswith
Dendswith
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators or string methods like endswith instead of startswith.