Back

How old are you?

Q1. Type in the following code and run it. Then describe in words what this program as a whole does.

1.  yourName = input("What's your name? >>> ")
2.  yourAge = int(input("How old are you? >>> "))
3.  print("Your name is",yourName)
4.  print("You are",yourAge,"years old.")
5.  if yourAge > 14:
6.      print("You can go to the cinema on your own!")
7.  else:
8.       print("You must stay at home.")
9. 
10. input("Press <ENTER> to quit ....")

Q2. Describe clearly what line 1 does.
Q3. Explain clearly why there is an int function in line 2 but not in line 1.
Q4. Delete the int and the brackets that go with it in line 2. What error message do you get? Put the int back in to line 2 and run the program again.
Q5. What is the purpose of the comma between "You are" and yourAge in line 4?
Q6. Discuss some sensible tests you would have to carry out to prove that this program works as intended?
Q7. Change the program so that you can go to the cinema if you are:

    1. older than 15
    2. older than or equal to 15
    3. younger than 10
    4. younger than or equal to 10
    5. aged exactly 12

Don't forget to test your program after each change!
Q8.
How can you print You must stay at home 5 times, with each line on a new line?
Q9. What would happen if you left out line 10?
Q10. Write a program that tells someone whether they passed or failed a test. It should ask them for their name and score out of a 100. 

Back