1.判断语句:
if`
a = int(input('请输入123中的一个数字:'))
if a == 1:
print(123)
if a == 2:
print(345)
if a == 3:
print('哈哈,你秀逗了!')
if
elif
month = int(input('请输入月份:'))
if 1 <= month <= 12:
if 3 <= month <= 5:
print(month,'春季')
elif 6 <= month <= 8:
print(month,'夏季')
elif 9 <= month <= 11:
print(month,'秋季')
elif month == 12 or month == 1 or month == 2:
print(month,'冬季')
else:
print('你脑袋坏掉了吧?')
while:
i = 0
while i < 5:
print('略')
i += 1
九九乘法表
i = 0
while i < 9:
i += 1
j = 0
while j < i:
j += 1
print('{}*{}={}'.format(j,i,j*i),end='\t')
print()
作业1:
i = 0
while i < 1000:
i += 1
if i == (i//100)**3 + ((i%100)//10)**3 + (i%10)**3 and 100 <= i < 1000:
print(i)
作业2.:
num = int(input('请输入一个数:'))
if num > 1:
for i in range(2, num):
if (num % i) == 0:
print(num, '不是质数')
print('{}*{}={}'.format(i, num//i, num))
break
else:
print(num, '是质数')
作业3.:
import random
person = int(input('请输入:石头(0),剪刀(1),布(2):'))
computer = random.randint(0, 2)
if person == 0:
print('玩家:石头')
elif person == 1:
print('玩家:剪刀')
else:
print('玩家:布')
if computer == 0:
print('电脑:石头')
elif computer == 1:
print('电脑:剪刀')
else:
print('电脑:布')
if person == 0 and computer == 1 or person == 1 and computer == 2 or person == 2 and computer == 0:
print('好厉害,你赢啦!')
elif person == computer:
print('加油!差一点!平局啦!')
else:
print('傻屌,你输啦,哈哈!')