Jul-29-2020, 12:33 PM
Hi All,
Really new to Python, and doing some coding to get use/understand it. I am working on a program, that creates a random number and the user needs to guess that random number. However the code I have done so far doesn't seem to work. Fo some reason the code keeps looping, even though I enter the correct number:
Thanks
Really new to Python, and doing some coding to get use/understand it. I am working on a program, that creates a random number and the user needs to guess that random number. However the code I have done so far doesn't seem to work. Fo some reason the code keeps looping, even though I enter the correct number:
import random
attempts = 0
guess = 0
number = random.sample(range( 1,100),1)
print("Welcome to the random number guessing game!")
print(number)
while guess != number:
guess = int(input("Please enter a number to guess: "))
attempts +=1
else:
print("Well done, you guesed the number")Any idea why would be very much appreciated. Thanks
