About the assignment of GUESS?

import random
times = 3
secret = random.randint
print ("- I love fish C studio -")
guess = 0
print ("guess which number the little turtle has in mind now:", end= ")
while (guess! = secret) and (times > 0):

temp = input()
guess = int(temp)
times = times - 1 -sharp -1
if guess == secret:
    print("")
    print("")
else:
    if guess > secret:
        print("~~~")
    else:
        print("~~~")
    if times > 0:
        print(":", end=" ")
    else:
        print("T_T")

print ("Game over, don"t play ^ _ ^")

question: why do you assign a value of 0 to GUESS in the code in the first place? What is the effect of this?

Mar.07,2021
The variable guess, defined by

is convenient to be called later by the program. The value of
guess can be arbitrary, such as guess = None, because int (temp) will be reassigned later.


because you are useful in while (guess! = secret) and (times > 0): if guess, is not declared earlier, an error will be reported.

Menu