1.13. Test Your Understanding#
Question 1
Which of these variables have valid names? Select all that apply.
lucky_number = 3 price($) = 2.78 4th_place = 'John' sigma2 = 10Solution
Remember that variables
Must start with a letter or an underscore character
Can only contain alpha-numeric (a-z, A-Z, 0-9) characters and underscores
lucky_number = 3Valid.
price($) = 2.78Invalid. This contains the characters
($)which are not allowed.4th_place = 'John'Invalid. Variables must start with a letter or an underscore character.
sigma2 = 10Valid.
Question 2
What is the type of the variable
x?x = 3.3
integer
float
string
list
Solution
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.py3", line 3, in <modlue> print("Total cost: ${}".format(cost * quantity)) TypeError: can't multiply sequence by non-int of type 'str'Solution
Solution is locked
Question 4
What is the value of
x?x = 2**2 + 2Solution
Solution is locked