使用的模块:

在此脚本中,我们将使用python的名为random的内置模块。

random模块:

random是Python的内置模块,它将帮助我们从列表或元素数组中选择任何随机元素。在此,我们将使用此模块代表计算机随机选择选项。

游戏规则为:Rock will be at 1.

Paper will be at 2.

Scissor will be at 3.

Rock vs Scissor => Rock wins.

Rock vs Paper => Paper wins.

Paper vs Scissor=> Scissor wins.

程序:# 导入模块

import random

Name=input("输入你的名字: ")

print("游戏规则如下:\n"

"1) Rock at 1.\n2) Paper at 2."

"\n3) Scissor at 3."

"\nRock vs Paper=> Paper wins"

"\nRock vs Scissor=>Rock wins"

"\nPaper vs Scissor=> Scissor wins")

# 如果进入循环

# 用户想要一次又一次地播放

while True:

print("Enter the choice:\n"

"1) Rock\n"

"2) Paper\n"

"3) Scissor")

# 用户转向

choice=int(input("User turn:"))

# 如果我们做出无效选择,那么我们将

# 再次接受输入,直到我们输入正确的

# 一

while choice<1 or choice>3:

choice=int(input("Invalid Choice Enter Again"))

if choice==1:

user_choice="Rock"

if choice==2:

user_choice="Paper"

if choice==3:

user_choice="Scissor"

print("User choice is "+user_choice)

# 用户转

print("Computers turn")

# 使用随机选择计算机

# 使用randint函数选择随机

# 从1到3

computer_choice=random.randint(1,3)

# 如果用户选择与计算机选择相同,则

# 再次,我们将选择直到。

while choice==computer_choice:

computer_choice=random.randint(1,3)

if computer_choice==1:

comp_choice="Rock"

if computer_choice==2:

comp_choice="Paper"

if computer_choice==3:

comp_choice="Scissor"

print("Computer choice is "+comp_choice)

# 获胜的条件

# 坚如磐石的条件

if (choice==1 and computer_choice==3) or (choice==3 and computer_choice==1):

print("Rock Wins")

result="Rock"

elif (choice==1 and computer_choice==2) or (choice==2 and computer_choice==1):

print("Paper Wins")

result="Paper"

else:

print("Scissor Wins")

result="Scissor"

if result==user_choice:

print(f"{Name} wins")

else:

print("Computer wins")

c=input("是否继续(Y/N)")

if c=="n" or c=="N":

break

输出:输入你的名字: Abhinav

游戏规则如下:

1) Rock at 1.

2) Paper at 2.

3) Scissor at 3.

Rock vs Paper=> Paper wins

Rock vs Scissor=>Rock wins

Paper vs Scissor=> Scissor wins

Enter the choice:

1) Rock

2) Paper

3) Scissor

User turn:2

User choice is Paper

Computers turn

Computer choice is Scissor

Scissor Wins

Computer wins

是否继续(Y/N)y

Enter the choice:

1) Rock

2) Paper

3) Scissor

User turn:1

User choice is Rock

Computers turn

Computer choice is Scissor

Rock Wins

Abhinav wins

If you want to Continue(Y/N)n

python循环剪刀石头布_Python中的剪刀石头布游戏相关推荐

  1. python循环迭代_Python中循环迭代的重做

    不,Python不直接支持redo.有一个选项可能会让嵌套循环变得非常糟糕,比如:for x in mylist: while True: ... if shouldredo: continue # ...

  2. python 元组遍历_Python中的for循环:元组、列表、字典的遍历和相互转化

    Python for循环可以遍历任何序列的项目,如列表.字符串.元组.字典.集合等序列类型. 语法: for循环的语法格式如下: for iterating_var in sequence:state ...

  3. python map用法_Python中ChainMap的一种实用用法

    Python部落(python.freelycode.com)组织翻译,禁止转载,欢迎转发. 简而言之ChainMap:将多个字典视为一个,解锁Python超能力. Python标准库中的集合模块包含 ...

  4. python循环指令_Python循环

    布尔运算 学习循环之前,先了解一个概念:布尔运算 布尔运算是数字符号化的逻辑推演法,包括联合.相交.相减.在图形处理操作中引用了这种逻辑运算方法以使简单的基本图形组合产生新的形体,并由二维布尔运算发展 ...

  5. python生成器迭代_python中的生成器和迭代器

    前言: 我们来了解一下什么是python中生成器.了解一下python生成器是什么,以及生成器在python编程之中能起到什么样的作用. 定义: 生成器和迭代器 通过列表生成式,我们可以直接创建一个列 ...

  6. python基本统计量_Python中简单统计量的计算

    本篇文章给大家带来的内容是关于Python中简单统计量的计算,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. 1.这些操作都要确保已经在电脑中安装好了Anaconda集成库,如果安装好 ...

  7. python解析原理_Python 中 -m 的典型用法、原理解析与发展演变

    在命令行中使用 Python 时,它可以接收大约 20 个选项(option),语法格式如下: python [-bBdEhiIOqsSuvVWx?] [-c command | -m module- ...

  8. python正则表达式空格_python中的正则表达式的使用

    一.正则表达式简介 正则表达式:又称正规表示式.正规表示法.正规表达式.规则表示式.常规表示法(英语:Regular Expression,在代码中常简写为regex.regexp或者是RE),是计算 ...

  9. python wraps模块_python中 wraps 的作用

    这里使用两段代码比较加入wraps装饰器后,函数打印的结果对比: 新建文件名:Testword 代码1:不加wraps装饰器 # coding=utf-8 from functools import ...

最新文章

  1. 秘钥加密码的登录模式
  2. 深度解析:国产化软硬件全景梳理
  3. 解决Kali LinuxVI编辑器无法复制问题
  4. 大数据项目一般金额多少_大数据分析师年薪一般多少?学什么专业才能从事大数据?...
  5. vue教程1:第一个页面HelloVue快速搭建
  6. 进入大厂的面试经验(P7)
  7. v5系列服务器后面板不存在以下哪款指示,群晖RS10613xs+ NAS服务器后面板简介
  8. 速读-A3基于注意力机制的神经网络处理器
  9. ORA-01157报错cannot identify/lock data file
  10. 小米小钢炮等常用蓝牙设备(音箱/键盘/打印机)连接电脑(Windows/Linux)使用笔记
  11. ISO体系认证是什么意思/ISO9001质量体系认证有什么用
  12. linux---dns/yum安装软件/定时任务
  13. 数组中元素与字节的关系
  14. 杭州(浙江)人才引进落户办理流程
  15. java微博分享代码实例
  16. 分享一个很香的k8s.gcr.io Docker镜像拉取方法
  17. 三位代表中国科技圈的85后技术男,他们眼中的AI是什么?
  18. php实现个人微信给自己好友发送消息
  19. Pytest如何重复执行N次脚本
  20. 上课用计算机的好处,多媒体课件的优点

热门文章

  1. 鞍山树人计算机学校宿舍,南开大学校务公报2016年第12期-信息公开.pdf
  2. 里加一列为1_风味人间2:大厨做的拔丝苹果,拉丝1米长,根根分明
  3. Idea SpringBoot工程提示 Error running 'xxxx': Command line is too long. In order to reduce its leng...
  4. 你知道这些吗?8款优秀的Vue UI组件库推荐,都能打开呦
  5. AMS1084电路图
  6. 阅读笔记:双核心Opteron处理器
  7. AMD芯片支持oracle数据库,ORACLE宣布支援AMD OPTERON处理器
  8. 三相四线相位表查错误接线方法与步骤
  9. 瑞波加入超级账本区块链联盟
  10. Java的JRE和JDK有什么区别和联系