I am trying to create a game where the user has to recall the numbers shown in the pop-up window. of they get any wrong, 'incorrect' is incremented by the number of numbers the have gotten wrong. if they get each number right, the score is incremented by 100. in this case, 300 should be outputted as the score. the score should only be incremented by 100 if what the user inputted is the same as array[i]
import random
array = []
#this appends three random numbers into an empty array
for i in range(3):
randomNumber = random.randint(0,100)
array.append(randomNumber)
# this function displays the random number for 1250 milliseconds
def randomNumberDisplay():
import tkinter as tk
root = tk.Tk()
root.title("info")
tk.Label(root, text=array).pack()
# time in ms
root.after(1250, lambda: root.destroy())
root.mainloop()
randomNumberDisplay()
#this function requires the user to enter the numbers displayed.
score = 0
def levelOne ():
incorrect = 0
i = 0
x = len(array)
for i in range (3):
userNumber = int(input("please enter the numbers you saw IN ORDER(press Enter when finished): "))
#if they enter the right number, they gain a score and get to move to the next level
while userNumber != array[i]:
print ("the numbers where: ", array[i])
incorrect = incorrect +1
("you got ", incorrect, "wrong")
if userNumber == array[i]:
score = correct + 100
i = i + 1
print ("you have ",score, "points")
levelOne ()
Example of what is displayed when playing the game: please enter the numbers you saw IN ORDER(press Enter when finished): 58 please enter the numbers you saw IN ORDER(press Enter when finished): 84 please enter the numbers you saw IN ORDER(press Enter when finished): 44 you have 100 points
Aucun commentaire:
Enregistrer un commentaire