当前位置 : 主页 > 编程语言 > python >

Python-If判断

来源:互联网 收集:自由互联 发布时间:2022-06-15
""" if语句 """cars = ['bwm', 'bens', 'audo', 'toyota'] for car in cars: if car == 'link': print(car.upper()) else: print(car.title()) """ if-elif-else 判断条件超过两个的情况下使用 """age = int(input('请输入你当前的年龄
""" if语句
"""cars = ['bwm', 'bens', 'audo', 'toyota']
for car in cars:
if car == 'link':
print(car.upper())
else:
print(car.title())

""" if-elif-else 判断条件超过两个的情况下使用
"""age = int(input('请输入你当前的年龄:'))
if age < 4:
print('4岁以下免费!')
elif 4 < age < 18:
print('4~18岁收费25美元!')
elif age >= 18:
print('18岁(含)以上收费40美元!')
else:
print('你输入的年龄有误,请重新输入!')

""" 练习题
"""player_score = 0game_choose = 'y'alien_colors = ['red', 'green', 'yellow']
print('当前有这些外星人:'+str(alien_colors))
while game_choose == 'y':
choose = input('请输入你要杀死的外星人:\n')
if choose == 'red':
player_score += 5 print('当前你获取了5分')
elif choose == 'green':
player_score += 10 print('当前你获取了10分')
elif choose == 'yellow':
player_score += 15 print('当前你获取了15分')
else:
game_choose = input('你是否还要继续y/n?\n')

print('当前你的游戏分数为:'+ str(player_score))
上一篇:Django API 开发:一个 Todo 应用的后端
下一篇:没有了
网友评论