Lesson 2 practice questions
Question 1
Create a variable that stores the value for pi.
Solution
pi=3.14
Question 2
What data type is stored in the variable pi? And why?
Solution
type(pi)
float
The variable pi has decimals, thus it is a float.
Question 3
Create a variable that stores Avogadro's number.
Solution
avogadro=6.02e23
Question 4
How do we check if Avogadro's number is greater than pi?
Solution
avogadro > pi
True
Question 5
Use the if
statement to print out something if Avogadro's number is greater than pi.
Solution
if avogadro > pi:
print("Avogadro's number is greater than pi")
else:
print("No conclusion can be made")
Avogadro's number is greater than pi
Question 6
Create a list of five random things that you can think of and then use a for
loop to print each item in the list.
Solution
town=["Curry","Thompson","Green","Igoudala","Durant"]
for player in range(0,5):
print(town[player])
Alternative solution
for player in town:
print(player)