判断语句=分支语句
逻辑运算 and or not(取反)
随机数:
石头剪刀布游戏
import random
player = int(input('请输入您要出的拳:石头(1)剪刀(2)布(3):'))
computer = random.randint(1,3)
print('玩家出的是%d,电脑出的是%d'%(player,computer))
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
python的计数基本上都是从0开始的 ,而不是从1开始。(编程时要注意)
九九乘法表,使用循环嵌套
i = 1
while i <= 9:
j = 1
while j <= i:
print('%d * %d = %d\t' % (i, j, i * j),end = '') #取消 一个公式之后的自动换行
j += 1
print('') #每行之后换行
i += 1