if ,while, if-elif-else ,语句

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('傻屌,你输啦,哈哈!')
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值