python from introduction to practice 07 exercise: 7-1-7-10

Posted by ghettopixel on Mon, 20 Dec 2021 22:30:38 +0100

Exercise 7-1: car rental
Write a program to ask users what kind of car they want to rent, and print a message. Here is an example.
Let me see if I can find you a Subaru.

car = input("Tell me the type of cars you want to rent: ")
print(f"Let me see if I can find you a {car.title()}.")

Exercise 7-2: restaurant reservation
Write a program to ask users how many people eat. If more than 8 bits, print a message indicating that there is no empty table; Otherwise, indicate that there is an empty table.

people_num = int(input("Please enter the number of people in the restaurant:"))
if people_num > 8:
    print('Sorry, we don't have any free tables')
else:
    print('Welcome to dinner')

Exercise 7-3:10 integer multiples
Let the user enter a number and indicate whether the number is an integer multiple of 10

num = int(input("Please enter any integer:"))
if num % 10 == 0:
    print("The number you entered is an integer of 10")
else:
    print("The number you entered is not an integer of 10")

Exercise 7-4: Pizza ingredients
Write a loop that prompts the user to enter a series of pizza ingredients and ends the loop when the user enters' quit '. Every time a user enters an ingredient, a message is printed indicating that we will add the ingredient to the pizza.

info = "\n Please enter the information you need pizza mixed ingredients:"
info += "\n Please enter'sign out'End procedure:"
while True:
    pizza = input(info)
    if pizza == 'sign out':
        break
    else:
        print(f"What you need pizza mixed ingredients:{pizza}")

Exercise 7-5: movie tickets
There is a cinema that charges different fares according to the age of the audience: those under the age of 3 are free; Visitors aged 3 to 12 charge $10; Viewers over the age of 12 charge $15. Please write a loop in which you ask the user's age and indicate their ticket price.

prompt = "\n Please enter your age:"
while True:
    age = input(prompt)
    if age == 'sign out':
        break
    age = int(age)
    if age < 3:
        price = 0
    if age >= 3 and age <= 12:
        price = 10
    elif age > 12:
        price = 15
    print(f"Your ticket price:{price} element")

Exercise 7-6: three ways out
Complete exercise 7-4 or exercise 7-5 in different ways, as follows in the procedure.
Use a conditional test in a while loop to end the loop.
Use the variable active to control when the loop ends.
Use the break statement to exit the loop when the user enters' quit '.

prompt = "\n Please enter the required pizza mixed ingredients:"
prompt += "\n Please enter'quit'End program:"
active = True
while active:
    message = input(prompt)
    if message == 'quit':
        break
    else:
        print(f"What you need pizza mixed ingredients:{message}")

Exercise 7-7: infinite loop
Write an endless loop and run it (to end the loop, press Ctrl + C or close the window showing the output)

x = 2
while x < 9:
    print(x)

Exercise 7-8: Deli
Create a named sandwich_orders list, which contains the names of various sandwiches, and then create one named finished_ Empty list of sandwiches. Traverse list sandwich_orders, for each sandwich, print a message, such as I made your tuna sandwich, and move it to the list finished_ In sandwiches. After all the sandwiches are made, print a message and list them.

sandwich_orders = ['tomato','meat','beef']
finished_sandwiches = []
for sandwich_order in sandwich_orders:
    print(f"i made your {sandwich_order} sandwich")
while sandwich_orders:
    new_sandwich = sandwich_orders.pop()
    finished_sandwiches.append(new_sandwich)
print(finished_sandwiches)

Exercise 7-9: spiced smoked beef is sold out
Use the list sandwich you created to complete exercises 7-8_ Orders and make sure 'pastrami' appears at least three times. Add such code near the beginning of the program: print a message indicating that the spiced smoked beef (pastrami) in the Deli is sold out; then use a while loop to delete all 'pastrami' in the list sandwich_orders. Make sure that the final list finished_sandwiches does not contain 'pastrami'.

print("The Deli is out of spiced smoked beef")
sandwich_orders = ['Spiced smoked beef','tomato','Spiced smoked beef','meat','beef','Spiced smoked beef']
finished_sandwiches = []
while 'Spiced smoked beef' in sandwich_orders:
    sandwich_orders.remove('Spiced smoked beef')
    print(sandwich_orders)
while sandwich_orders:
    sandwich = sandwich_orders.pop()
    finished_sandwiches.append(sandwich)
print(finished_sandwiches)

Exercise 7-10: Dream Resort
Write a program to investigate the user's dream resort. Use tips similar to the following and write a code block to print the survey results.
If you could visit one place in the world, where would you go?

dream_places = {}
active = True
while active:
    name = input("Please enter your name:")
    place = input("Please enter where you want to go:")
    dream_places[name] = place
    repeat = input("Whether to participate in the survey? Please enter yes or No:")
    if repeat == 'no':
        active = False
print("Findings")
for name,place in dream_places.items():
    print(f"{name} want to go to {place}")