Q:

Create a Python project to guess a number that has randomly selected

0

Create a Python project to guess a number that has randomly selected

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#https://github.com/sarbajoy/NumberGuess/blob/master/numberguess.py
import random
number=random.randrange(0,100)
guessCheck="wrong"
print("Welcome to Number Guess")

while guessCheck=="wrong":
	response=int(input("Please input a number between 0 and 100:"))
	try:
		val=int(response)
	except ValueError:
		print("This is not a valid integer. Please try again")
		continue
	val=int (response)
	if val<number:
		print("This is lower than actual number. Please try again.")
	elif val>number:
		print("This is higher than actual number. Please try again.")
	else:
		print("This is the correct number")
		guessCheck="correct"

print("Thank you for playing Number Guess. See you again")

Sample Output:

Welcome to Number Guess
Please input a number between 0 and 100:6
This is lower than actual number. Please try again.
Please input a number between 0 and 100:25
This is higher than actual number. Please try again.
Please input a number between 0 and 100:15
This is higher than actual number. Please try again.
Please input a number between 0 and 100:10
This is lower than actual number. Please try again.
Please input a number between 0 and 100:11
This is lower than actual number. Please try again.
Please input a number between 0 and 100:123
This is higher than actual number. Please try again.
Please input a number between 0 and 100:12
This is the correct number
Thank you for playing Number Guess. See you again

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now