0
0
Pythonprogramming~10 mins

Numeric values (int and float behavior) 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'
Afloat
Bstr
Cint
Dbool
Attempts:
3 left
💡 Hint
Common Mistakes
Using float() instead of int() when you want a whole number.
Using str() which keeps the value as text.
2fill in blank
medium

Complete the code to get the decimal number 3.14 from a string.

Python
pi = [1]('3.14')
print(pi)
Drag options to blanks, or click blank then click option'
Aint
Bbool
Cstr
Dfloat
Attempts:
3 left
💡 Hint
Common Mistakes
Using int() which cannot convert decimal strings.
Using str() which keeps the value as text.
3fill in blank
hard

Fix the error in the code to correctly convert the float 7.0 to an integer.

Python
number = 7.0
result = [1](number)
print(result)
Drag options to blanks, or click blank then click option'
Aint
Bfloat
Cstr
Dbool
Attempts:
3 left
💡 Hint
Common Mistakes
Using float() which keeps the decimal.
Using str() which converts to text.
4fill in blank
hard

Fill both blanks to create a dictionary with numbers as keys and their squares as values, only for numbers greater than 3.

Python
squares = {x: x[1]2 for x in range(1, 6) if x [2] 3}
print(squares)
Drag options to blanks, or click blank then click option'
A**
B>
C<
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using + instead of ** for squaring.
Using < instead of > in the condition.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase keys, values as floats, and only include values 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>
Dfloat(v)
Attempts:
3 left
💡 Hint
Common Mistakes
Using v directly instead of converting to float.
Using < instead of > in the condition.
Not converting keys to uppercase.