人生中的第一篇博客,剪刀石頭布的小游戲
# -*- codeing = utf-8 -*-
# @Time : 2021/10/22 14:36
# @Author : 寧洪康
# @File : 剪刀石頭布.py
# @Software : PyCharm
import random
choices = ["Rock", "Scissors", "Paper"]
computer = random.choice(choices)
player = False
cpu_score = 0 #電腦初始成績
player_score = 0 #玩家初始成績
while True:
player = input("Rock, Scissors or Paper" ).title()
# 判斷電腦與玩家選擇
if player == computer:
print("tie!")
elif player == "Rock":
if computer == "Paper":
print("you lose!", computer, "covers", player)
cpu_score += 1
else:
print("you win!", player, "smashes", computer)
player_score += 1
elif player == "Paper":
if computer == "Scissors":
print("You lose!", computer, "cut", player)
cpu_score += 1
else:
print("You win!", player, "covers", computer)
player_score += 1
elif player == "Scissors":
if computer == "Rock":
print("You lose...", computer, "smashes", player)
cpu_score += 1
else:
print("You win!", player, "cut", computer)
player_score += 1
elif player == 'E': #輸出成績,跳出循環
print("Final Scores:")
print(f"computer:{cpu_score}")
print(f"Player:{player_score}")
break
else:
print("That's not a valid play. Check your spelling!")
computer = random.choice(choices)