Professional Documents
Culture Documents
Type Example
literal int 1
module random
keyword import
Q3 Look at the screenshot for Guess the Number. The results are currently printed as:
Modify your Guess the Number code so that it prints the results like this:
(You only need to include the part of the code that you modified.)\
print('The number was ' + str(number) + ', but you guessed ' + guess + '.')
Design
1. When the game starts, the user is asked to guess
a number between 1 and 10.
2. After the user enter an answer, the user is
prompted to enter the enter key.
3. The computer gives the computer’s selected
number.
4. The computer display the number the user
guessed.
Function Test
1. Are the instructions displayed?
2. Is the player prompted to enter the number?
3. Does the program wait for the player to press
enter?
4. Does the program display the correct answer?
5. Does the program display users answer?
6. Does the game end?
7. Restart the game
Is the generated number random?
Algorithms:
Main Algorithm:
Display instructions
Prompt player for guess
Display result
Display users guess
Algorithm blocks:
Display instructions
Line 1
Prompt player for guess
Line 2: guess = input('What is the number?')
Display result
Display computer’s selected number
Display users guess
Display the player’s guessed number
Code:
#Import function:
import random
#Coding:
def main():
print('I am thinking of a number between 1 and 10.')
number = random.randint(1,10)
guess = input('what is the number?')
print('The number was',number)
print('You guessed',guess)
main()