0
0
Pythonprogramming~10 mins

Type conversion (int, float, string) 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 convert the string '123' to an integer.

Python
num = [1]('123')
print(num)
Drag options to blanks, or click blank then click option'
Aint
Bbool
Cstr
Dfloat
Attempts:
3 left
💡 Hint
Common Mistakes
Using float() instead of int() changes the type to float.
Using str() keeps it as a string, no conversion.
Using bool() converts to True or False, not a number.
2fill in blank
medium

Complete the code to convert the integer 45 to a float.

Python
num = [1](45)
print(num)
Drag options to blanks, or click blank then click option'
Abool
Bstr
Cint
Dfloat
Attempts:
3 left
💡 Hint
Common Mistakes
Using int() keeps it as an integer.
Using str() converts to a string, not a number.
Using bool() converts to True or False.
3fill in blank
hard

Fix the error in the code to convert the float 3.14 to a string.

Python
text = [1](3.14)
print(text)
Drag options to blanks, or click blank then click option'
Aint
Bfloat
Cstr
Dbool
Attempts:
3 left
💡 Hint
Common Mistakes
Using int() causes loss of decimal part.
Using float() keeps it as a float, no string conversion.
Using bool() converts to True or False.
4fill in blank
hard

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

Python
lengths = {word: [1] for word in words if len(word) [2] 3}
Drag options to blanks, or click blank then click option'
Alen(word)
B<=
C>
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' includes words of length 3 or less.
Using 'word' instead of 'len(word)' gives the word itself, not length.
Using 'len(word)' with '<=' filters wrong words.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase keys and values only if the value is greater than 0.

Python
result = {{ [1]: [2] for k, v in data.items() if v [3] 0 }}
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
C>
Dk.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'k.lower()' makes keys lowercase, not uppercase.
Using '<' instead of '>' filters wrong values.
Using 'k' instead of 'k.upper()' keeps original case.