Test Your Understanding

1.13. Test Your Understanding#

Question 1

Which of these variables have valid names? Select all that apply.

  1. lucky_number = 3
    
  2. price($) = 2.78
    
  3. 4th_place = 'John'
    
  4. sigma2 = 10
    
Solution

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 = 3

Valid.

price($) = 2.78

Invalid. This contains the characters ($) which are not allowed.

4th_place = 'John'

Invalid. Variables must start with a letter or an underscore character.

sigma2 = 10

Valid.

Question 2

What is the type of the variable x?

x = 3.3
  1. integer

  2. float

  3. string

  4. 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))
  1. Total cost: $1.251.251.25
    
  2. Total cost: $3.75
    
  3. 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 + 2
Solution

Solution is locked