# Python练习题

### 一、使用while循环输入1-10，其中不包括7

```1 number = 0
2 while number<10:
3     number +=1
4     if number == 7:
5         continue
6     print(number)  ```

### 二、求1-100的所有数的和

```1 count = 1
2 sum = 0
3 flag =True
4 while flag:
5     sum = sum + count
6     count += 1
7     if count > 100:
8         break
9 print(‘1-100的总和是：‘,sum)```

### 三、输出1-100内的所有奇数

```1 odd = 1
2 while odd <=100:
3     print(odd)
4     odd += 2```

### 四、输出1-100内的所有偶数

```1 even = 0
2 while even <=100:
3     even += 2
4     if even > 100:
5         continue
6     print(even)```

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

``` 1 odd = 1
2 even = 2
3 odd_sum = 0
4 even_sum = 0
5 while odd < 100:
6     odd_sum = odd_sum + odd
7     odd += 2
8 while even < 100:
9     even_sum = even_sum + even
10     even += 2
11 print(‘odd_sum:‘,odd_sum,‘even_sum:‘,even_sum)
12 count_sum = odd_sum - even_sum
13 print("1-2+3-4+5...99的所有数的和是:",count_sum)```

### 六、用户登陆（三次机会重试）

```count_number = 3
flag = True
while flag:
user_name = input("请输入你的用户名:")
print(‘用户名与登录密码输入正确，用户登录成功‘)
break
if count_number == 3:
print(‘用户名或登录密码输入不一致，你还有两次机会‘)
elif count_number == 2:
print(‘用户名或登录密码输入不一致，你还有一次机会‘)
else:
print(‘用户名或登录密码输入不一致，你的机会已经用完，请过5分钟后再试‘)
count_number -= 1
if count_number < 1:
break```

Python练习题

(0)
(0)