難以理解while(True)函數應該如何適應代碼。另外不知道如果這是我想循環遊戲,直到計算機或用戶點擊點的所需量使用正確的事(這在一開始的用戶輸入作爲發)不理解While(True)循環 - Python 2.7
import random
def main():
print
print "----------------------------------"
print "Welcome to Rock, Paper, Sciccors! "
print "----------------------------------"
rounds = input("How many points to win?: ")
user_choice = input("Choose Rock = 1 , Paper = 2 or Sciccors = 3: ")
user_score = 0
computer_score = 0
if user_choice == 1:
print "You chose Rock"
elif user_choice == 2:
print "You chose Paper"
elif user_choice == 3:
print "You chose Sciccors"
else:
print " Wrong! Choose 1, 2 or 3!"
computer_choice = random.randrange(1, 4)
if computer_choice == 1:
print "Computer chose Rock"
elif computer_choice == 2:
print "Computer chose Paper"
elif computer_choice == 3:
print "Computer chose Sciccors"
def checkResults(computer_choice, user_choice):
checkResults = computer_choice - user_choice
if computer_choice - user_choice == 0:
print("Draw!")
user_score += 1
computer_score += 1
elif computer_choice - user_choice == 1 or computer_choice - user_choice == -2:
print("Computer wins")
computer_score += 1
elif computer_choice - user_choice == -1 or computer_choice - user_choice == 2:
print("You win!")
user_score += 1
print (" Computer {} , You {}" .format(computer_score, user_score))
while(True):
if computer_score == rounds or user_score == rounds:
main()
else:
break
你可以使用無需語法錯誤的代碼更新答案嗎?最好也刪除很多空行。 – totoro