用python实现简单的石头剪刀布小游戏
代码如下:
# -*- coding:utf-8 -*-
# 实现剪刀石头布
# 随机数生成、input、print、if、elif、while
import random #引入模块
if __name__ == "__main__":
#定义菜单
print("欢迎来到我的世界!!!")
print("1.开始游戏")
print("2.退出游戏")
# 获取用户从控制台输入的信息
option = input("请输入你的选项:")
while True:
if option == "1":
player = input("请出招:1、剪刀;2、石头;3、布;\n") #input返回结果是string类型
computer = random.randint(1,3) #返回的数据类型是int 转换类型 str()
computer = str(computer) #将int类型转换为string类型
if player == computer:
print("【平手】")
elif player == "1" and computer == "2":
print("【你完了】")
elif player == "1" and computer =&#