2024-01-28_Python的if语句

2024-02-02  本文已影响0人  微笑碧落

1. Python的if语句基本语法

age = 12 
if age < 4: 
  price = 0 
elif age < 18: 
  price = 5 
elif age < 65: 
  price = 10
print("Your admission cost is $" + str(price) + ".")
if 5 < age <20:
  pass

banned_users = ['andrew', 'carolina', 'david']
user = 'marie'
if user not in banned_users:
    print(user.title() + ", you can post a response if you wish.")

car = 'subaru' 
print("Is car == 'subaru'? I predict True.") 
print(car == 'subaru') 
print("\nIs car != 'audi'? I predict False.") 
print(car != 'audi')
age = 3
if 5 < age < 18:
    price = 3
else:
    price = 8
print(f"Your admission cost is ${price}.")
上一篇 下一篇

猜你喜欢

热点阅读