import random
userscore = 0
computerscore = 0
print("Welcome to the Rock, Paper, Scissors Game")
while True:
print("User Score = ", userscore, " Computer Score = ", computerscore)
print("Rock, Paper or Scissors?")
userweapon = str(input())
print("You chose ", userweapon)
computerweapon = random.randint(1,3)
if computerweapon == 1:
computerweapon = "Rock"
elif computerweapon == 2:
computerweapon = "Paper"
else:
computerweapon = "Scissors"
print("Computer chose ", computerweapon)
if userweapon == computerweapon:
print("You chose the same Weapon, it's a draw.")
elif userweapon == "Rock" and computerweapon == "Paper":
print("Computer Point.")
computerscore +=1
elif userweapon == "Rock" and computerweapon == "Scissors":
print("User Point.")
userscore +=1
elif userweapon == "Paper" and computerweapon == "Rock":
print("User Point.")
userscore +=1
elif userweapon == "Paper" and computerweapon == "Scissors":
print("Computer Point.")
computerscore +=1
elif userweapon == "Scissors" and computerweapon == "Rock":
print("Computer point.")
computerscore +=1
elif userweapon == "Scissors" and computerweapon == "Paper":
print("User Point.")
我該如何要求用戶輸入他們要支付多少分,以及如何在輸入()達到時使用此信息結束遊戲?如何在Python中完成這個Rock,Paper,Scissors遊戲?
我知道這段代碼看起來很糟糕,但我是初學者,這是我能做的最好的。感謝您的閱讀,我會爲最佳答案投票。
因我的範圍是什麼(VAR):是什麼意思?我看到了很多,但我不明白! – pythonswag
範圍(var)返回從0到var的項目列表。因爲我在範圍內迭代生成的列表,然後放棄列表。 – GoingTharn
只需輸入'range(5)'即可。它打印出[[0,1,2,3,4]',實際上是爲你製作一份清單(比這更復雜一點,但它有這種效果)。 'for'循環將每個元素依次分配給我,直到完成爲止。你可以忽略我,或者你可以打印出來讓用戶知道他們正在玩哪一回合。 – mhlester