Python -day 5
1 >>> cars = ['audi' , 'bmw' , 'subaru' , 'toyota'] 2 >>> for car in cars: 3 >>> if car == 'bmw': 4 >>> print(car.upper()) 5 >>> else: 6 >>> print(car.title()) 7 Audi 8 BMW 9 Subaru 10 Toyota
1 >>> age = 12 2 >>> if age < 4: 3 >>> price = 0 4 >>> elif age < 18: 5 >>> price = 5 6 >>> elif age < 65: 7 >>> price = 10 8 >>> else: 9 >>> price = 5 10 >>> print("Your admission cost is $" + str(price) + ".") 11 Your admission cost is $5.
1 >>> requested_toppings = [] 2 >>> if requested_toppings: 3 >>> for requested_topping in requested_toppings: 4 >>> print("Adding "+requested_topping + ".") 5 >>> print("\nFinished making your pizza!") 6 >>> else: 7 >>> print("Are you sure you want a plain pizza?") 8 Are you sure you want a plain pizza?优质内容筛选与推荐>>