[英]Python doesn't accept my input, what I'm I doing wrong?
我正在為策划游戲創建代碼,我認為一切都應該是完美的,但是當我嘗試編寫第一個輸入所需的信息時(在這種情況下,像“ R”這樣的顏色,無論我做什么都沒關系這樣做將直接跳到打印上(“您必須引入四種顏色,不要多,不少!”)
誰能幫我嗎???
這是代碼:
colours=["R", "G", "B", "Y", "W", "R", "P"]
attempts=0
game=True
codemaker=random.sample(colours,4)
print (codemaker)
while game:
white_points=0
black_points=0
guessed_colour=""
player_guess=input().upper()
attempts+=1
if len(player_guess) != len(codemaker):
print ("You have to introduce four colours, no more, no less! ")
continue
用print做一些輕量級的調試,您將看到代碼完全按照您的要求執行:不打印(“您必須引入四種顏色,不多不少!”)同樣4:
import random
colours=["R", "G", "B", "Y", "W", "R", "P"]
attempts=0
game=True
codemaker=random.sample(colours,4)
print(len(codemaker), codemaker)
while game:
white_points=0
black_points=0
guessed_colour=""
player_guess=input().upper()
attempts+=1
print(player_guess, len(player_guess))
if len(player_guess) != len(codemaker):
print("You have to introduce four colours, no more, no less! ")
continue
測試...
4 ['W', 'B', 'R', 'G']
abcde
ABCDE 5
You have to introduce four colours, no more, no less!
WBRG
WBRG 4
@#$%^U
@#$%^U 6
You have to introduce four colours, no more, no less!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.