python循环语句选择题_python学习-7 条件语句 while循环 + 练习题

Python

Python开发

Python语言

python学习-7 条件语句 while循环 + 练习题

1.死循环

while 1 == 1:print('ok')

结果是一直循环

2.循环

count =0while count < 10:print(count)

count= count +1

print(error)

3.练习题

~ 使用while循环输出1 2 3 4 5 6   8 9 10

count = 1

while count <= 10 : #或者count < 11

if count == 7:print( ) #也可以添加pass,什么也不执行

else:print(count)

count= count + 1

执行结果:

1

2

3

4

5

6

8

9

10Process finished with exit code 0

~ 求1-100的所有数的和

a = 1b=0while a < 101:

b= b +a

a= a + 1

print(b)

输出结果:

5050Process finished with exit code 0

~求1-100内所有的奇数

n = 1

while n < 101:

js= n % 2

if js ==0:print( )else:print(n)

n= n + 1

输出结果:

1

3

5

7

9

11

13

15

17

19

21

23

25

27

29

31

33

35

37

39

41

43

45

47

49

51

53

55

57

59

61

63

65

67

69

71

73

75

77

79

81

83

85

87

89

91

93

95

97

99

~ 求1-100内所有的偶数

a = 1

while a < 101:

b= a % 2

if b ==0:print(a)else:passa= a + 1

输出结果:

2

4

6

8

10

12

14

16

18

20

22

24

26

28

30

32

34

36

38

40

42

44

46

48

50

52

54

56

58

60

62

64

66

68

70

72

74

76

78

80

82

84

86

88

90

92

94

96

98

100Process finished with exit code 0

内容来源于网络,如有侵权请联系客服删除

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值