467,092 Members | 1,148 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,092 developers. It's quick & easy.

Hello everyone thanks in advance for solving my program. I have written a guessing ga

Bit
import random

def levels():
menu = ' '
while(menu != "X" or menu != "x"):
print("..............GUESSING GAME............")
print(".......................................")
print("(1) Numbers from 1 to 20")
print("(2) Numbers from 21 to 100")
print("(X) Exit")
print(".......................................")
menu=input("Enter a choice:")
if(menu=="1"):
guess=comparision
elif(menu=="2"):
guess=comparision1
elif(menu=="X" or menu =="x"):
print("Exit chosen")
else:
print("Invalid choice")
return menu
def input_function():
guess=int(input("Enter your guess:"))
return guess

def random_function():
random_number=random.randint(1,20)
return random_number

def random_function1():
random_number1=random.randint(21,100)
return random_number1

def comparision(guess,random_number):
if(guess<random_number):
print("sorry,guess again your guess is too low")
elif(guess>random_number):
print("sorry,guess again your guess is too high")
else:
print("Yay,congrats.You have guessed correctly.")

def comparision1(guess,random_number1):
if(guess<random_number1):
print("sorry,guess again your guess is too low")
elif(guess>random_number1):
print("sorry,guess again your guess is too high")
else:
print("Yay,congrats.You have guessed correctly.")
level=levels()
guess=input_function()
random_number=random_function()
random_number1=random_function1()
1 Week Ago #1
  • viewed: 1747
Share:
1 Reply
dev7060
Expert 256MB
What's the question?
1 Week Ago #2

Post your reply

Sign in to post your reply or Sign up for a free account.

By using this site, you agree to our Privacy Policy and Terms of Use.