day13 6.6hw python第一天
python第一天作业
1、使用while循环输出1 2 3 4 5 6 8 9 10
x
1
i=1
2
while i<=10:
3
print(i,end=' ')
4
i += 1
5
![](https://images2015.cnblogs.com/blog/1142847/201707/1142847-20170713153402228-1716976564.png)
2、求1-100的所有数的和
xxxxxxxxxx
1
1
print(sum(range(101)))
![](https://images2015.cnblogs.com/blog/1142847/201707/1142847-20170713153402822-1208547599.png)
3、输出 1-100 内的所有奇数
xxxxxxxxxx
1
1
s = sum([i for i in range(1,101) if i %2 ==1])
2
print(s)
![](https://images2015.cnblogs.com/blog/1142847/201707/1142847-20170713153403384-1173734339.png)
4、输出 1-100 内的所有偶数
xxxxxxxxxx
1
1
s = sum([i for i in range(1,101) if i %2 ==0])
2
print(s)
![](https://images2015.cnblogs.com/blog/1142847/201707/1142847-20170713153405697-2059551796.png)
5、求1-2+3-4+5 ... 99的所有数的和
xxxxxxxxxx
1
1
print(sum(range(1,100)))
![](https://images2015.cnblogs.com/blog/1142847/201707/1142847-20170713153406243-960540882.png)
6、用户登陆(三次机会重试)
xxxxxxxxxx
1
11
1
i = 0
2
while i<3:
3
name = input('name :')
4
password = input('password :')
5
if name == 'egon' and password == '123':
6
print('login successful')
7
break
8
else:
9
print('输入错误,还有%s次机会'%(2-i))
10
i += 1
![](https://images2015.cnblogs.com/blog/1142847/201707/1142847-20170713153407212-758040450.png)
![](https://images2015.cnblogs.com/blog/1142847/201707/1142847-20170713153407634-580715886.png)