第一天作业

1.求1-100的总和

1 count = 0
2 int = 0
3 while count < 100:
4     count += 1
5     #print(count)
6     int += count
7     print(int)

2.使用while循环输出1 2 3 4 5 6 8 9 10

1 count = 0
2 while count < 10:
3     count += 1
4     if count == 7:
5         continue #到循环首,不执行下方代码
6     print(count)
1 count = 0
2 while count < 10:
3     count += 1
4     if count == 7:
5         pass #跳过
6     else:
7         print(count)

3.取奇数偶数

count = 0
while count < 100:
    count += 1
    if count % 2 == 0:
        print('偶数:'+  str(count))
    else:
        #pass
        print('奇数:'+  str(count))
count = 1
while count < 100:
    print(count)
    count += 2

 4.1-2+3-4+5-6。。。。99的总和

sum = 0
count = 0
while count < 99:
    count += 1
    #print(count)
    if count % 2 == 0:
        sum -= count #如果为偶数就减
    else:
        sum += count #如果为奇数就+
print(sum)
#最后结果为50

5.3次机会猜数字游戏

print('接下来我们进行一个猜数字的游戏')
print('你共有3次机会,猜出我心中所想的1-10其中一个')
count = 0
while count < 3:
    ni = int(input('请输入1-10其中一个数字:'))
    if ni == 8:
        print('恭喜你猜对了!')
        break
    else:
        print('猜错了!你还有' + str(2-count) + '次机会')
    count += 1
count = 0
while count < 3:
    username = input('请输入账号:')
    password = input('请输入密码:')
    if username == '陈俊' and password == '123':
        print('登录成功!')
        break
    elif count == 2:
        print('错误次数超过3次!')
    else:
        print('登录失败,请检查!你还有' + str(2-count) + '次输入机会!')
    count += 1

 

转载于:https://www.cnblogs.com/chengoudan/p/10359580.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值