I'm trying to make a number generator with a high number without using shell but it's not working. each time i write yes, it's displaying the same number. help

#you need to write the whole word "yes" or "no" for it to work. from random import randint num = randint(1, 100000000000000000000000000000000000000) while True: print(" ") print(" ") print("Welcome To Number Generator.") print("Would You Like To Get A Number?") answer = input("Enter yes or no: ") if answer == "yes": print(num) elif answer == "no": quit() else: print("Please enter yes or no.")

You only generate a random number once, if you want a different random number every time, the code responsible for generating the random number should be in the loop

1 Like

there is the while true loop

meaning
num = randint(1, 100000000000000000000000000000000000000)
should be inside the while loop

1 Like

also I cant get a number that has less digits then 10000000000000000000000000000000000000. how do i do it

you can get a number that has less digits that that, but there’s only a 1 in 10 chance of that happening using the code you have now.

here’s a simulation of the program:

index = 0 simulated_inputs = ["yes", "yes", "yes", "no"] def input(message): global index if index < len(simulated_inputs): print(message) print("simulated input >>> ", end = " ") to_return = simulated_inputs[index] print(to_return) index += 1 return to_return #you need to write the whole word "yes" or "no" for it to work. from random import randint while True: num = randint(1, 100000000000000000000000000000000000000) print(" ") print(" ") print("Welcome To Number Generator.") print("Would You Like To Get A Number?") answer = input("Enter yes or no: ") if answer == "yes": print(num) elif answer == "no": #quit() break else: print("Please enter yes or no.")

you can also make the number of digits random:

max_number_of_digits = 12
num_of_digits = randint(1, max_number_of_digits)
num = randint(1, int("1" + ("0" * num_of_digits)) )
from random import randint max_number_of_digits = 12 num_of_digits = randint(1, max_number_of_digits) num = randint(1, int("1" + ("0" * num_of_digits)) ) print(num)
1 Like