1.13. Test Your Understanding#
Question 1
Which of these variables have valid names? Select all that apply.
lucky_number = 3
Explanation
Valid. This name starts with a letter and only contains letters and an underscore.
price($) = 2.78
Explanation
Invalid. Variable names cannot contain (, $, or ).
4th_place = 'John'
Explanation
Invalid. Variable names cannot start with a number.
sigma2 = 10
Explanation
Valid. This name starts with a letter and only contains letters and a number.
Explanation
Variable names must start with a letter or an underscore and can only contain letters, numbers, and underscores.
Question 2
What is the type of the variable x?
x = 3.3
integer
float
string
list
lock
This solution is locked.
Question 3
What would you expect to be the output of the following code?
cost = '1.25'
quantity = 3
print('Total cost: ${}'.format(cost * quantity))
Total cost: $1.251.251.25
Total cost: $3.75
Traceback (most recent call last):
File "main.py", line 3, in <module>
print("Total cost: ${}".format(cost * quantity))
TypeError: can't multiply sequence by non-int of type 'str'
lock
This solution is locked.
Question 4
What is the value of x?
x = 2**2 + 2
Solution
Solution is locked