so i was doing this little game in python and ran across a problem. I wanted to randomize the randomNumber variable. It does change every time i run , but when i print the number it keeps on showing the same number. Example , I choose to play the game 3 times , and my game will make me enter 3 value , but the random number is the same for all 3.
Code :
import random
def guessingNumber():
userPlayTimes = int(input('How many times you wanna play : '))
randomNumber = random.randrange(1,10)
userScore = 0
for x in range(1,userPlayTimes+1):
userGuess = int(input('Please enter your random Guess : '))
print(userScore , randomNumber)
if userGuess == randomNumber:
userScore += 1
return userScore
print(userScore)
Result :
Q : How many times you wanna play : 5
Please enter your random Guess : 1
0 3 (score , randomNumber)
Q : Please enter your random Guess : 2
0 3 (score , randomNumber)
Q : Please enter your random Guess : 3
0 3 (score , randomNumber)
1 (overall score)
Please don't mind if I m bad at writing because this is my first time using stackoverflow for asking quesitons.
Aucun commentaire:
Enregistrer un commentaire