程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Scissors stone paper games, python implementation

編輯:Python

The first blog in my life , Scissors stone cloth games

# -*- codeing = utf-8 -*-
# @Time : 2021/10/22 14:36
# @Author : Ning Hongkang
# @File : scissors .py
# @Software : PyCharm
import random
choices = ["Rock", "Scissors", "Paper"]
computer = random.choice(choices)
player = False
cpu_score = 0 # Initial score of computer
player_score = 0 # Player's initial score
while True:
player = input("Rock, Scissors or Paper" ).title()
# Judge the choice between computer and player
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': # Output results , Out of the loop
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)


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved