首页 > 其他 > 详细

Day 001 Exercise

时间:2018-03-16 21:26:21      阅读:220      评论:0      收藏:0      [点我收藏+]
# 1、使用while循环输入 1 2 3 4 5 6     8 9 10
count = 0
while count < 10:
    count  += 1
    if  count == 7:
        continue
    print(count)


# 2、求1 - 100的所有数的和
sum = 0
x = 1
while x < 101:
    sum = sum + x
    x +=1
print(sum)


# 3、输出 1-100 内的所有奇数
odd = 0
while odd < 100:
    odd += 1
    if odd % 2 == 1:
        print(odd)


# 4、输出 1-100 内的所有偶数
even = 0
while even < 100:
    even += 1
    if even % 2 == 0:
        print(even)


# 5、求1-2+3-4+5 ... 99的所有数的和
num = 1
sum = 0
while num < 100:
    if num % 2 == 1:
        sum = sum + num
    elif num % 2 == 0:
        sum = sum - num
    num += 1
print(sum)


# 6、用户登陆(三次机会重试)
count = 0
while count < 3:
    count += 1
    user = input("请输入用户名")
    passWord = input("请输入密码")
    if user == "evic" and passWord == "123":
        print("Welcome")
    elif count > 2:
        print("go away")
    else:
        print(please try again)

 

Day 001 Exercise

原文:https://www.cnblogs.com/evicxixi/p/8585207.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!