python条件判断和循环语句
2019-01-31 19:27
453 查看
1、if else 语句
#需要使用int进行强制类型转换,否则接下去会报错 #python格式要求严格,代码缩进要注意 while (True): score = int(input("what's your score?")) if score>= 90: print('Excellent') if score < 60: print('Fail') else: print('Good Job')
结果:
C:\Users\Admin\Anaconda3\python.exe D:/winterVocation/GeekTime/day1.py what's your score?95 Excellent Good Job what's your score?20 Fail what's your score?65 Good Job what's your score?
2、for循环
sum = 0 for number in range(11): sum = sum + number print(sum)
结果:
C:\Users\Admin\Anaconda3\python.exe D:/winterVocation/GeekTime/day1.py 55 Process finished with exit code 0
3、while循环
sum = 0 number = 1 while number < 11: sum = sum + number number = number + 1 print(sum)
结果:
C:\Users\Admin\Anaconda3\python.exe D:/winterVocation/GeekTime/day1.py 55 Process finished with exit code 0
相关文章推荐
- Python中的条件判断语句与循环语句用法小结
- python基础(3)--条件判断循环语句与列表解析,生成器
- Python中的条件判断语句与循环语句用法小结
- Python入门笔记(4)_ 控制流:条件判断和循环语句
- [Python] - 条件判断和循环语句
- python基础-06-条件判断、循环语句
- python 列表处理,for循环语句,if条件判断
- python基础知识- 条件判断语句和循环语句
- Python While循环语句 Python 编程中 while 语句用于循环执行程序,即在某条件下,循环执行某段程序,以处理需要重复处理的相同任务。其基本形式为: while 判断条件:
- Python之 If条件判断、While循环语句
- Linux shell的条件判断、循环语句及实例
- python中的条件选择语句和循环语句
- python学习笔记 条件判断和循环
- Python入门5_条件循环语句
- 【学习笔记】Python条件判断-If语句
- for语句中间的为判断条件,符合了可循环
- 【Python⑥】python的缩进,条件判断和循环
- python的for、while循环和if条件语句
- Python条件语句和循环语句
- Python基础知识——条件判断与循环