1. 输入用户年龄,根据年龄打印不同的内容
age = 10
if age >= 18:
print 'you can see these movie'
else:
print "you can not see these movie"
Python代码的缩进规则。具有相同缩进的代码被视为代码块,缩进请严格按照Python的习惯写法:4个空格,不要使用Tab,更不要混合Tab和空格,否则很容易造成因为缩进引起的语法错误。
注意: if 语句后接表达式,然后用:表示代码块开始。
2. 如果成绩达到60分或以上,视为passed。
假设Bart同学的分数是75,请用if语句判断是否能打印出 passed
score = 75
if score >= 60:
print 'passed'
else:
print 'not passed'
Python之 if-elif-else
3. 如果按照分数划定结果:
90分或以上:excellent
80分或以上:good
60分或以上:passed
60分以下:failed
请编写程序根据分数打印结果。
# -*- coding: utf-8 -*-
score = 95
if score >= 90:
print 'excellent'
elif score >= 80:
print 'good'
elif score >= 60:
print 'passed'
else:
print 'failed'