# Have you been to a game arcade?
# Which of the games are your favourite?
# Are you ready to design one?
''' Task 1: Number Buzzer Game'''
print("**** Task 1: ****")
print()
# Write a “Guess the Number” game, where a player has to guess a number between 10 and 20. Let's assume that the number to guess is 15.
# Hint: Use the while loop.
print("Welcome to the Guess the Number game! guess a number between")
import random
x = int(input("Press zero to start playing."))
counter = 0
if x == 0:
ans = random.randint(10,20)
num = int(input("Guess a number between ten and twenty"))
while counter != 3:
if num<10:
print("Number is lesser than 10")
num=int(input("Guess a number between 10 and 20: "))
elif num>20:
print("Number is greater than 20")
num=int(input("Guess a number between 10 and 20: "))
elif num == ans:
print("YOU WIN CONGRATULATIONS! I HOPE YOU COME BACK TO PLAY AGAIN!!")
break
else:
print("Try again!!")
counter += 1
num=int(input("Guess a number between 10 and 20: "))
# Did you program work?
# Excellent!!
# Let's add some checks to the game, you have written:
# If the number is lesser than 10, you must give a warning message and ask them to guess again
# If the number is greater than 20, you must give a warning message for the same and ask them to guess again
# If the number is right, then you display a congratulatory message
# Now write the if statements, to check the above conditions ?
# The if statement should look like:
#if num<10:
# print("Number is lesser than 10")
# num=int(input("Guess a number between 10 and 20: "))
# elif num>20:
# print("Number is greater than 20")
# num=int(input("Guess a number between 10 and 20: "))
# else:
# print("Try again!!")
# num=int(input("Guess a number between 10 and 20: "))
# Now all you have to do is include the above if statement within the while statement you have written.
# Can you do it and then click on Run to see if your program runs successfully.
''' Task 2: Break the loop'''
print("**** Task 2: ****")
print()
# Now let's bring in a twist in the program you wrote in Task 1. # You need to modify the program, in a way that it allows only 3 chances to guess the number.
# Do you want to give it a try? [Wait for the student to respond and checkout the student’s program]
# Uncomment the statements below and click Run.
#ctr=1
#while(ctr<=3):
# num=int(input("Guess a number between 10 and 20: "))
# if num<10:
# print("Number is lesser than 10")
# elif num>20:
# print("Number is greater than 20")
# elif num==15:
# print("Bingo!! You guessed right!")
# break
# else:
# print("Try again!!")
#ctr=ctr+1
# When asked to input the number try the following: 1,24, 15.
# Analyze the program and tell me what are the changes made to the program and what is the new command that has been included.
# You are right. The new command included in the program is break.
# The break statement breaks the loops and starts executing the next line of code after the block.
''' Task 3: To quit or not to quit'''
print("**** Task 3: ****")
print()
# Write a program that takes numbers between 1 and 100 from the user.
# To quit entering numbers the user needs to press 0.
# The program should then display the sum and the product of the numbers.
counter = 0
while counter != 1:
num = int(input("Enter your number from 1 to 100"))
if num >=1 and num <= 100:
x+=num
print("TO HIGH OR LOW")
elif num == 0:
counter += 1
print(f"BYE!!! your score is {x}")
'''Great! You are getting good with creating loops and checking conditions during an iteration.'''
To embed this project on your website, copy the following code and paste it into your website's HTML: