您的位置:首页 > 编程语言 > Python开发

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: