Commit 26a2f50c by BellCodeEditor

auto save

parent 69c75b80
Showing with 60 additions and 4 deletions
import random
player=input("请出拳:石头/剪刀/布") player=input("请出拳:石头/剪刀/布")
print("玩家出拳:"+player) print("玩家出拳:"+player)
import random
list["石头","剪刀","布"] list["石头","剪刀","布"]
computer=random.choice(list) computer=random.choice(list)
print("电脑玩家出拳:"+computer) print("电脑玩家出拳:"+computer)
if player==computer:
if player in list:
if player==computer:
print("平局") print("平局")
elif(player=="石头" and computer=="布")or(player=="布" and computer=="剪刀")or(player=="剪刀" and computer=="石头"): elif(player=="石头" and computer=="布")or(player=="布" and computer=="剪刀")or(player=="剪刀" and computer=="石头"):
print("失败") print("失败")
else: else:
print("胜利") print("胜利")
else:
print("输入错误")
三种或三种以上的判断用 if。。。elif。。。else elifelse。。。if的缩写 意思否则如果
当用到随机功能时,random
需要导入random模块 import random
其中choice()是在列表中随机抽取一个元素
random.choice
示例:
list=["a","b","c","d"]
random.choice(list) 功能 列表中随机选一项
知识要勤于复习 才是自己的
print("hello"+"world!")
"+" 连接字符串作用
如果有数值需要转化成字符串才能连接
使用turtle模块应先用import导入
import turtle
再进行画图
创建画笔
pen=turtle.Pen() P为大写
使用画笔的功能时,我们要在前面加上pen中间用点连接
例如:pen.forward()
pen.left()
print("你好") 功能 在控制台输出内容
input("你叫什么") 功能 在控制台输入内容 在英文为 输入的意思 就是请输入指令
查看任何导入模块 ctrl + 鼠标左键
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment