7-1 汽车租赁
Car=input("What do you want to rent a car?\n")
print('Let me see if I can find you a ',Car)
Output:
/Library/Frameworks/Python.framework/Versions/3.6/bin/learning/bin/python /Users/macbook/PycharmProjects/learning/test
What do you want to rent a car?
Mercedes-Benz
Let me see if I can find you a Mercedes-Benz
Process finished with exit code 0
7-2 餐馆订位
number=input("How many people to have meal ?\n")
number=int(number)
if(number>8):
print("Sorry! No free table!")
else:
print("We have free table")
Output 1:
/Library/Frameworks/Python.framework/Versions/3.6/bin/learning/bin/python /Users/macbook/PycharmProjects/learning/test
How many people to have meal ?
9
Sorry! No free table!
Process finished with exit code 0
Output 2:
/Library/Frameworks/Python.framework/Versions/3.6/bin/learning/bin/python /Users/macbook/PycharmProjects/learning/test
How many people to have meal ?
1
We have free table
Process finished with exit code 0
7-5 电影票
message="Please enter your age (Enter 'quit' to quit): "
while (True):
Age=input(message)
if(Age=='quit'):
break;
Age=int(Age)
if(Age<3):
print("Free")
elif(Age<13):
print("Ten dollars")
else:
print("Fifteen dollars")
Output:
/Library/Frameworks/Python.framework/Versions/3.6/bin/learning/bin/python /Users/macbook/PycharmProjects/learning/test
Please enter your age (Enter 'quit' to quit): 1
Free
Please enter your age (Enter 'quit' to quit): 8
Ten dollars
Please enter your age (Enter 'quit' to quit): 18
Fifteen dollars
Please enter your age (Enter 'quit' to quit): quit
Process finished with exit code 0
7-6 三个出口
message="Please enter your age (Enter 'quit' to quit): "
Active=True
while (Active):
Age=input(message)
if(Age=='quit'):
break;
Age=int(Age)
if(Age<3):
print("Free")
elif(Age<13):
print("Ten dollars")
else:
print("Fifteen dollars")
Output:
/Library/Frameworks/Python.framework/Versions/3.6/bin/learning/bin/python /Users/macbook/PycharmProjects/learning/test
Please enter your age (Enter 'quit' to quit): 1
Free
Please enter your age (Enter 'quit' to quit): 4
Ten dollars
Please enter your age (Enter 'quit' to quit): 20
Fifteen dollars
Please enter your age (Enter 'quit' to quit): quit
Process finished with exit code 0
7-8 熟食店
sandwich_orders=['beef','chicken','tuna']
finished_sandwiches=[]
print('sandwich_orders:',end='')
print(sandwich_orders)
while sandwich_orders:
sandwich=sandwich_orders.pop()
finished_sandwiches.append(sandwich)
print("I made your",sandwich,'sandwich')
print('finished_sandwiches:',end='')
print(finished_sandwiches)
Output:
/Library/Frameworks/Python.framework/Versions/3.6/bin/learning/bin/python /Users/macbook/PycharmProjects/learning/test
sandwich_orders:['beef', 'chicken', 'tuna']
I made your tuna sandwich
I made your chicken sandwich
I made your beef sandwich
finished_sandwiches:['tuna', 'chicken', 'beef']
Process finished with exit code 0
7-9 五香烟熏牛肉卖完了
sandwich_orders=['pastrami','beef','pastrami','chicken','tuna','pastrami']
print("Original:",sandwich_orders)
print("Sorry!The pastrami sandwich has sold out!")
while 'pastrami' in sandwich_orders:
sandwich_orders.remove('pastrami')
print("New:",sandwich_orders)
Output:
/Library/Frameworks/Python.framework/Versions/3.6/bin/learning/bin/python /Users/macbook/PycharmProjects/learning/test
Original: ['pastrami', 'beef', 'pastrami', 'chicken', 'tuna', 'pastrami']
Sorry!The pastrami sandwich has sold out!
New: ['beef', 'chicken', 'tuna']
Process finished with exit code 0