Python 编程迷你项目 (附源码) 一

了解RPA:
www.i-search.com.cn

学习RPA
https://support.i-search.com.cn/

下载RPA:
https://www.i-search.com.cn/?from=csdn

大家也可根据项目的目的及提示,自己构建解决方法,提高编程水平。
① 骰子模拟器
目的:创建一个程序来模拟掷骰子。

提示:当用户询问时,使用 random 模块生成一个 1 到 6 之间的数字。

在这里插入图片描述

② 石头剪刀布游戏
目标:创建一个命令行游戏,游戏者可以在石头、剪刀和布之间进行选择,与计算机 PK。如果游戏者赢了,得分就会添加,直到结束游戏时,最终的分数会展示给游戏者。

提示:接受游戏者的选择,并且与计算机的选择进行比较。计算机的选择是从选择列表中随机选取的。如果游戏者获胜,则增加 1 分。

import random
choices = [“Rock”, “Paper”, “Scissors”]
computer = random.choice(choices)
player = False
cpu_score = 0
player_score = 0
while True:
player = input(“Rock, Paper or Scissors?”).capitalize()
# 判断游戏者和电脑的选择
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"CPU:{cpu_score}")
print(f"Plaer:{player_score}")
break
else:
print(“That’s not a valid play. Check your spelling!”)
computer = random.choice(choices)

来源:艺赛旗RPA社区 掉进悬崖的小白

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值