I just started python last week and made this code project to test my learning. This code is supposed to display a Zombie Apocalypse and the user arrives at the military base. While proving that they are human, the code generates a random 5 number pass code to make the game unique every time. The user has to type to code in, kind of like a CAPTCHA. But when I run the code, after the user types the pass code and presses enter, the pass code entering part of the code starts to repeat. I think this may be because of the while loop if the user gets the pass code wrong. I don’t have much experience to see the problem. I tried rewriting the whole thing, it didn’t even try to work because of so many syntax error messages. If you can please help me it would be appreciated.
I also am working on it on replit, so you can check the code there:
https://replit.com/@PratikKharel/Something2?v=1
import time
import sys
import random
def typing(text):
for character in text:
sys.stdout.write(character)
sys.stdout.flush()
time.sleep(0.07)
def fasttyping(text):
for character in text:
sys.stdout.write(character)
sys.stdout.flush()
time.sleep(0.02)
def fastertyping(text):
for character in text:
sys.stdout.write(character)
sys.stdout.flush()
time.sleep(0.005)
passcode = "".join(str(random.randint(1, 9)) for _ in range(5))
typing("Hello fellow surviver.")
time.sleep(0.8)
print("")
typing("Welcome to the Zombie Military Base: ")
time.sleep(0.8)
print("")
typing("Lambda 17 ")
time.sleep(1)
print("")
typing("This is where you will begin your survival story. ")
print("")
time.sleep(1)
passwordright = False
typing(f"Type [{passcode}] to verify as a Human")
time.sleep(0.5)
typing(".")
time.sleep(0.3)
typing(".")
time.sleep(0.3)
typing(".")
time.sleep(0.3)
def start():
print("")
typing(">>> ")
o = (int(input("")))
if o != passcode:
typing("Please try again.")
print("")
start()
elif o == passcode:
passwordright = True
fasttyping("#@$____!#%$!@___WE_ARE_COMING_FOR_YOU__@$@#$___@#$")
time.sleep(0.2)
sys.stdout.flush()
time.sleep(1)
fastertyping(
'\r____________________________________________________________')
time.sleep(0.5)
print("")
typing("Since you are here, you will need a nickname.")
print("")
fasttyping("What will !@#$%^&@")
time.sleep(0.2)
sys.stdout.flush()
time.sleep(1)
fastertyping('\rWhat will your name be?')
while passwordright == False:
start()
start()
>Solution :
That’s because you are trying to compare between different data types at:
if o != passcode:
o is of type int, while passcode is a string.
Just delete the int casting in o = (int(input(""))) to:
o = (input())