Python 习题一

it2022-05-15  61

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

# Author:Tony.lou i = 1 while i < 11: if i == 7: pass else: print (i) i+=1

 2.求1-100所有的和

# Author:Tony.lou i = 0 n = 0 while i <100: tmp = i % 2 if tmp == 0: n = n - i else: n = n + i i = i + 1 print(n) print(sum(i for i in range(1,101)))

 

 3.输出1-100内所有基数

i = 0 while i < 101: tmp = i % 2 if tmp != 0: print(i) else: pass i+=1 for i in range(1,100,2): print(i) View Code

 

 

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

# Author:Tony.lou i = 0 n = 0 while i <100: tmp = i % 2 if tmp == 0: n = n - i else: n = n + i i = i + 1 print(n)

 5.用户三次登录

count = 0 while count < 3: user = input('user:') password = input('password:') if user == 'tony' and password =='Omd': print('welcome') print('........') break else: print('error..try again') count += 1 View Code

 

转载于:https://www.cnblogs.com/lyj821202/p/9000545.html

相关资源:130道python练习题.zip

最新回复(0)