剪刀石头布小游戏,python实现

人生中的第一篇博客,剪刀石头布的小游戏

# -*- 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)

你可能感兴趣的:(游戏,python,开发语言,游戏程序)