Created by Nichola Wilkin Ltd.
More sub programs
Work in pairs to create these programs in Python. Save them with a
sensible name.
Challenge 4
Create a sub program that will display this menu.
In the main program ask the user to enter two numbers and then display the menu.
It they enter +, -, * or / perform the calculation, if they enter anything other than a
correct symbol display the message “Incorrect selection” and display the menu
again. Keep displaying the menu until they do enter something that is correct.
Once they have selected a correct operator then display the message “The answer
is...[answer]”.
Challenge 5
You can create a random number
Define a sub program that will ask the user to
using the following code:
pick a low and a high number, and then
generate a random number between those
two values and store it in a variable called
“comp_num”.
Define another sub program that will give the instruction “I am thinking of a
number…” and then ask the user to guess the number they are thinking of.
Define a third sub program that will check to see if the comp_num is the same as the
user’s guess. If it is, it should display the message “Correct, you win”, otherwise it
should keep looping, telling the user if they are too low or too high and asking them
to guess again until they guess correctly.
© Nichola Wilkin Ltd 2019 Page 1
[Link]