I'm having some issues with my python program. I need to generate a list of numbers from 1 to 100 for use inside of a variable.
import random
import time
tries = 0
sumcoin = 0
list = (1, 100)
def run():
while True:
global sumcoin
global tries
correct = (list)
guessed = (list)
if guessed == correct:
print (f"\033[0;32;40mCorrect Guess! It was {correct}, found after {tries} attempts.\033[0;37;40m.")
sumcoin=sumcoin+1
print (f"You guessed {sumcoin} times Correctly!")
tries = 0
sumcoin=sumcoin+1
time.sleep(1)
tries=tries+1
run()
The code is intended to generate a number from 1 to 100, guess it, and if it guesses wrongly then it will restart the process I will make the variable random with random.choice() or randint. This is the snippet output:
user@user:~ $ python3 list.py
Correct Guess! It was (1, 100), found after 0 attempts..
You guessed 1 times Correctly!
Correct Guess! It was (1, 100), found after 1 attempts..
You guessed 3 times Correctly!
Correct Guess! It was (1, 100), found after 1 attempts..
You guessed 5 times Correctly!
Correct Guess! It was (1, 100), found after 1 attempts..
You guessed 7 times Correctly!
Correct Guess! It was (1, 100), found after 1 attempts..
You guessed 9 times Correctly!
Correct Guess! It was (1, 100), found after 1 attempts..
You guessed 11 times Correctly!
Correct Guess! It was (1, 100), found after 1 attempts..
As you can see, it only guessed the exact variable "(1, 100)". I am trying to make a random number out of 100 each time a new number is guessed. I searched online for the issue, but could not find any reliable results that could help me. Any and all assistance would be really, really appreciated.
Aucun commentaire:
Enregistrer un commentaire