# Revision Questions

There will be test next week on the work we’ve done so far.  Here are some questions for you to practice:

1. Prompt the user to enter their (name). Print out “Hello” (name) “I hope you’re well”
2. Prompt the user to input two numbers.  Output the average of those two numbers.
3. Prompt the user to enter their age.  If they are aged between 4 and 16 output “You should be at school”
4. Create a list called months, containing the months in the year.  Now print out all the months, one after the other
5. Use a for loop to print out the following numbers: 7,14,21, … 63,70,77
6. Convert the String “I never saw a purple cow” to uppercase and output the resulting string.

# Autumn 1 Test

Write programs to solve the following. Submit your answers as a word document here.

1. Prompt the user “What’s the capital of France?” If they enter “Paris” print out “Correct!” otherwise print “Wrong!”
2. Create a list containing the following houses “Rowntree”, “Wrigley”, “Lord”, “Mothersill”, “Birley”, “Hall”.  Print out the list, one after the other.
3. The area of a triangle is half x base x height.  Prompt the user to enter the base and height of a triangle and then print out the area.
4. Use a for loop to print out the 6 times table up to 12 x 6. Print it in the format “4 x 6 = 24”
5. Create a list containing the days of the week. Use string handling functions to print out the list in uppercase and then in lowercase.

#### Extension

Draw a house using turtle graphics. You get 1 point for each of the following features

• Roof
• Door
• 1 Window
• 2 Windows
• Chimney
• Garden Path

# Code Golf: Songs

In code golf, the aim is to write a program with the lowest number of characters.

How short can you make the program to print out one of  the following songs?

# Autumn 2 Test

Do the following questions.  Submit your code and output as screenshots on a Word Document here.

1. Prompt the user to enter the number of bits in a byte.  If they answer 8 print correct, otherwise print “try again.”  The program should loop until the user gets the correct answer.
2. Use a for loop to print out the 5 times table.
3. Create a list containing the following names:  Ann, Sue, Andy, Steve, Charlotte, Craig, Mark, Raza.  Now print out all the names using a for loop.
4. An online sweet shop charges for shipping as follows:  One box, £5.99; two to five boxes £7; more than five boxes, free.   Prompt the user to enter the number of boxes bought and output the shipping cost.
5. In Python, open a file object with write access to a file called “cheese.txt”.
1. Write the following three names to the file: Cheddar, Lancashire, Mozzarella
2. Close the file object

# Revision Questions 2

## The Problems

Write programs to do the following. Take screenshots of your code and upload them as a word document.

1. Prompt the user to enter the number of bits in a byte. If they answer 8 print correct, otherwise print “try again.” The program should loop until the user gets the correct answer.
2. Use a for loop to print out the 5 times table.
3. Create a list containing the following names: Ann, Sue, Andy, Steve, Charlotte, Craig, Mark, Raza. Now print out all the names, one after the other
4. Create a dictionary called french containing the following data: chien – dog, chat – cat, vache – cow, cheval – horse, mouton – sheep. Loop through the keys printing out the associated values.

## Extension

1. Follow the link to find the text of the poem THE RIME OF THE ANCIENT MARINER: http://www.textfiles.com/etext/FICTION/coleridge-rime-371.txt
2. Copy the text into a file called rime.txt
3. Write a python program that reads rime.txt into a list.
4. Modify your program so that it counts how many lines there are in the list.
5. Modify the program further so that it counts how many words there are in the list.
6. Modify the program so that it counts how many times the word “the” appears.
7. Can you count the frequency of letters in the poem? In other words, how many times does ‘a’ appear, ‘b’ appear, ‘c’ appear and so on…

## Time in Words

Given a time in numbers we can convert it into words. For example:

• 5:00 Five o’clock
• 5:10 Ten minutes past five
• 5:15 Quarter past five
• 5:30 Half past five
• 5:45 Quarter to six
• 5:47 Thirteen minutes to six

Write a program which inputs two numbers (the first between 1 and 12, the second between 0 and 59 inclusive) and then prints out the time they represent, in words. You should follow the format of the examples above. Your program should then terminate.

``````Sample run
Hours: 4
Minutes: 12
Twelve minutes past four``````

## Partial Solution

The following code should start you off. It will answer some times correctly but not all. You will have test the code and then add extra lines to fix it.

``````times = ["o'clock","One","two","three","four", "five", "six",
"seven","eight","nine","ten","eleven","twelve","thirteen","fourteen",
"quarter","sixteen","seventeen","eighteen","nineteen","twenty",
"twenty one","twenty two","twenty three","twenty four",
"twenty five","twenty six","twenty seven","twenty eight",
"twenty nine","Half past"]

hours = 4
minutes = 12

if minutes>30:
print(times[60-minutes]+ " to " + times[hours])
else:
print(times[minutes] + " past " + times[hours])``````

Test the code with examples given at the top of the screen.

The test data at the top of the screen is not exhaustive. Think of some other times that are not covered. Adjust your code accordingly.

Have you considered all the options? There is some test data at the bottom of this page…

Paste your completed code to a word document

#### Extension

1. Which times, when written in words, have the longest length?
2. Write a program that outputs times in 24 hour clock format, eg 13 hours 0 minutes outputs 13:00 and 9 hours 15 mins prints out 09:15.  You must include the leading 0s!

## Time in Words Test Data

1. 3 o’clock
2. 6:25
3. 7:45
4. 12:00 (noon)
5. 0:00 (midnight)
6. 12:55
7. 0:05
8. 0:30