Python homeWork-1

2019-07-24 09:20:44来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

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

1 count = 0
2 while count < 10:
3     count = count + 1
4     if count == 7:
5         print(" ",end = "")
6         continue
7     else:
8         print(count,end = " ")

2.求1 - 100的所有的数的和

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

3.输出1 - 100的所有的奇数

 1 count = 1
 2 row = 0
 3 while count <= 100:
 4     if count % 2 == 1:
 5         row = row + 1
 6         print("%2d"%(count),end = "")
 7         if row % 10 == 0:
 8             print()
 9         else:
10             print(" ",end = "")
11     count = count + 1

4.输出1 - 100 的所有的偶数

 

 1 count = 1
 2 row = 0
 3 while count <= 100:
 4     if count % 2 == 0:
 5         row = row + 1
 6         print("%2d"%(count),end = "")
 7         if row % 10 == 0:
 8             print()
 9         else:
10             print(" ",end = "")
11     count = count + 1

 

 

 

5.求1+2+3+4+5...99的所有数的和

 

1 count = 1
2 sum = 0
3 while count <= 99:
4     sum += count
5     count = count + 1
6 print(sum)

 

 

 

6.用户登录(三次重试机会)

 1 times = 1
 2 username = input("Please input your username:")
 3 while times <= 3:
 4     if username == "John":
 5         print("Welcome Back!",end = "")
 6         break
 7     else:
 8         if times % 3 != 0:
 9             print("Wrong input!")
10         else:
11             print("Please check out your username after 5 minutes!",end = "")
12             break
13     times = times + 1
14     username = input("Please input your username:")

 


原文链接:https://www.cnblogs.com/Fantac/p/11171990.html
如有疑问请与原作者联系

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:记录一下为什么开通博客

下一篇:python数据库-MySQL与python的交互(52)