设为首页 加入收藏

TOP

Python homeWork-1
2019-07-11 20:10:55 】 浏览:11
Tags:Python homeWork-1

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:")

 


编程开发网
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇列表 下一篇python学习-36 文件处理b模式

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

array(4) { ["type"]=> int(8) ["message"]=> string(24) "Undefined variable: jobs" ["file"]=> string(32) "/mnt/wp/cppentry/do/bencandy.php" ["line"]=> int(217) }