0
我試圖創建一個簡單的while循環,它會在「分數」達到一定數量後停止。while循環的輪數在遊戲中
我能夠使它低於在工作的時候設置「發」的3個數字:
var_1 = 0
var_2 = 0
while var_1 < 3 and var_2 < 3:
choice = raw_input("Choose apple or orange.")
if choice.lower() == 'a' or choice.lower() == 'apple':
var_1 += 1
print "You like apples, huh?"
print "Apples: " + str(var_1) + "; Oranges: " + str(var_2)
elif choice.lower() == 'o' or choice.lower() == 'orange':
var_2 += 1
print "You like oranges, huh?"
print "Apples: " + str(var_1) + "; Oranges: " + str(var_2)
print "Game over."
if var_1 == 3:
print "Apples are more popular."
elif var_2 == 3:
print "Oranges are more popular."
但....如果我有一個線的raw_input的代碼round_number讓播放器確定回合數,然後將該條件設置爲該變量,則不起作用:
var_1 = 0
var_2 = 0
round_number = raw_input("How many rounds would you like to play?")
while var_1 < round_number and var_2 < round_number:
choice = raw_input("Choose apple or orange.")
if choice.lower() == 'a' or choice.lower() == 'apple':
var_1 += 1
print "You like apples, huh?"
print "Apples: " + str(var_1) + "; Oranges: " + str(var_2)
elif choice.lower() == 'o' or choice.lower() == 'orange':
var_2 += 1
print "You like oranges, huh?"
print "Apples: " + str(var_1) + "; Oranges: " + str(var_2)
print "Game over."
if var_1 == round_number:
print "Apples are more popular."
elif var_2 == round_number:
print "Oranges are more popular."
我在做什麼錯?