if语句以及random包
猜拳代码
import random
player = int(input("请出拳 石头(1) 剪刀(2) 布(3)"))
computer = random.randint(1,3)
if (player == 1 and computer == 2) or (player == 2 and computer == 3) or (player == 3 and computer == 1):
print("你赢了")
elif player == computer:
print("平手")
else:
print("你输了")
while基础语法
i = 1
while i <= 5:
print("hello")
i = i + 1
while循环嵌套
row = 0
while row < 5:
print("*" * (row + 1))
row += 1
打印九九乘法表
#\t在控制台输出一个制表符,协助在输出文本时垂直方向保持对齐
#\n在控制台输出一个换行符
row=1
while row<=9:
col=1
while col<=row:
print("%d * %d = %d"%(col,row,row*col),end="\t")
col+=1
row+=1
print(end="\n")