我上周剛開始使用 python 並製作了這個代碼項目來測試我的學習。此代碼應該顯示殭屍啟示錄,並且用戶到達軍事基地。在證明他們是人類的同時,該代碼會生成一個隨機的 5 位數密碼,使遊戲每次都獨一無二。用戶必須輸入代碼,有點像 CAPTCHA。但是當我運行代碼時,在用戶輸入密碼並按回車鍵後,密碼輸入部分代碼開始重複。我認為這可能是因為如果用戶獲取密碼錯誤,則可能是因為 while 循環。我沒有太多經驗看問題。我嘗試重寫整個內容,但由於語法錯誤消息太多,它甚至沒有嘗試工作。如果你能幫助我,我將不勝感激。
我也在 replit 上研究它,所以你可以檢查那裡的代碼: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()
那是因為您試圖在以下位置比較不同的數據類型:
if o != passcode:
o
是 type int
,而 whilepasscode
是一個字符串。
只需刪除int
投射o = (int(input("")))
到:
o = (input())
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句