Guessing game - Answers
Q1. Type the code in and get it working.
Q2. Replace the print lines with:
print(
"""Welcome to Guess the number!
I've thought of a number between 1 and 100.
How many attempts do you need to guess it?
"""
)
Q3. Change
the_number = random.randint(1,100)
to a smaller range e.g.
the_number = random.randint(1,20)
Q4. Replace
the_number = random.randint(1,100)
with
the_number = (random.randrange(1,100,2)
Care should be taken to start with an ordd number.
Q5. Replace
the_number = random.randint(1,100)
with
the_number = (random.randrange(2,202,2)
Care should be taken to start with the number 2 and end with 202 (the range goes up to but does not include the top limit).
Q6.
import random
print(
"""Welcome to Guess the number!
Let's begin ......
"""
)
#display a random number
print(random.randint(20,50))
#Do they want another?
guess =input("Would you like another number? Please enter Y for yes and any other key for no >>> ")
while guess=="Y":
print(random.randint(20,50))
guess = input("Another go >>> ")
print("Thank you and goodbye.")
input("\n\nPress <ENTER> to quit >>> ")
Q7. There are a number of ways. One way is to use the string function upper(). Change
while guess=="Y":
to
while guess.upper()=="Y":