码迷,mamicode.com
首页 > 其他好文 > 详细

Day 001 Exercise

时间:2018-03-16 21:36:10      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:ase   body   while循环   use   lease   col   password   post   count   

# 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

标签:ase   body   while循环   use   lease   col   password   post   count   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!