Python Quiz1mid
Python Quiz1mid
Republicof
ofthe
thePhilippines
Philippines
P OLYTECHNIC U
POLYTECHNIC UNIVERSITY
NIVERSITY OF THE P
OF THE PHILIPPINES
HILIPPINES
Sto.Tomas
Sto.Tomas Campus,
Campus, Sto.Tomas,
Sto.Tomas, Batangas
Batangas
Instructions: Please provide screenshots of the source code and the corresponding output for
the following programs. Submit a printed hard copy on the scheduled date and time as
announced. Late submissions will result in a deduction of points or may not be accepted.
1. Rental Car: Write a program that asks the user what kind of rental car they would like.
Print a message about that car, such as “ Let me see if I can find you a Subaru.”
Codes:
Output:
2. Restaurant Seating: Write a program that asks the user how many people are in their
dinner group. If the answer is more than eight, print a message saying they’ll have to
wait for a table. Otherwise, report that their table is ready.
Codes:
Output:
3. Pizza Toppings: Write a loop that prompts the user to enter a series of pizza toppings
until they enter a ‘quit’ value. As they enter each topping, print a message saying you’ll
add that topping to their pizza.
Codes:
Output:
4. Dream Vacation: Write a program that polls users about their dream vacation. Write a
prompt similar to If you could visit one place in the world, where would you go? Include a
block of coden that prints the results of the poll.
Codes:
Output:
5. Favorite Book: Write a function called favorite_book() that accepts one parameter, title.
The function should print a message, such as One of my favorite books is Alice in
Wonderland. Call the function, making sure to include a book title as an argument in the
function call.
Codes:
Output:
6. Cities: Write a function called describe_city that accepts the name of a city and its
country. The function should print a simple sentence, such as Reykjavik is in Iceland.
Give the parameter for the country a default value. Call your function for three different
cities, at least one of which is not in the default country.
Codes:
Output:
1
Republic
Republicof
ofthe
thePhilippines
Philippines
P OLYTECHNIC U
POLYTECHNIC UNIVERSITY
NIVERSITY OF THE P
OF THE PHILIPPINES
HILIPPINES
Sto.Tomas
Sto.Tomas Campus,
Campus, Sto.Tomas,
Sto.Tomas, Batangas
Batangas
7. City Names: Write a function called city_country() that takes in the name of a city and its
country. The function should return a string formatted like this: “Santiago, Chile”
Call your function with atleast three city-country pairs, and print the values that are
returned.
Codes:
Output:
8. Messages: Make a list containing a series of short tect messages. Pass the list to a
function called show_messages(), which prints each text message.
Codes:
Output:
Codes:
Output:
10. Printing Models: Put the functions for the example printing_models.py in a separate file
called printing_functions.py. Write an import statement at the top of printing_models.py,
and modify the file to use the imported functions.
Codes:
Output:
11. File Extensions: Create a program that display a filename without the file extension,
like some file browsers do. Used the appropriate Python method to do this program.
Codes:
Output:
12. Number Eight: Write addition, subtraction, multiplication, and division operations that
each result in the number 8. Your output should be four lines, with the number 8
appearing once on each line.
Codes:
Output:
13. Greetings: Create a list that prints each person name and a specific message for each
of them. The text of each message should be the same, but each message should be
personalized with the person’s name.
Codes:
Output:
2
Republic
Republicof
ofthe
thePhilippines
Philippines
P OLYTECHNIC U
POLYTECHNIC UNIVERSITY
NIVERSITY OF THE P
OF THE PHILIPPINES
HILIPPINES
Sto.Tomas
Sto.Tomas Campus,
Campus, Sto.Tomas,
Sto.Tomas, Batangas
Batangas
14. Seeing the World: Think of at least five places in the world you’d like to visit. Store the
locations in a list. Make sure the list is not in alphabetical order.
- Print your list in its original order.
- Print your list in alphabetical order without modifying the actual list.
- Print your list in reverse-alphabetical order.
Codes:
Output:
15. Summing a Hundred: Make a list of the numbers from one to one hundred, and then
use min() and max() to make sure your list actually starts at one ends at one hundred.
Also, use the sum() function to see how quickly Python can add a hundred numbers.
Codes:
Output:
16. Buffet: A buffet-style restaurant offers only five basic foods. Think of five simple foods,
and store them in a tuple.
- Use a for loop to print each food the restaurant offers.
- Try to modify one of the items, and make sure that Python rejects the change.
- The restaurant changes its menu, replacing two of the items with different foods. Add
a line that rewrites the tuple, and then use a for loop to print each of the items on the
revised menu.
Codes:
Output:
17. Stages of Life: Write an if-elif-else chain that determines a person’s stage of life. Set a
value for the variable age, and then for example, if a person is less than 2 years old,
print a message that the person is a baby, etc.
Codes:
Output:
18. Rivers: Make a dictionary containing three major rivers and the country each river runs
through. One key-value pair might be ‘nile’:’egypt’.
- Use a loop to print a sentence about each river, such as The Nile runs through
Egypt.
- Use a loop to print the name of each river included in the dictionary.
- Use a loop to print the name of each country included in the dictionary.
Codes:
Output:
19. Cities: Make a dictionary called cities. Use the names of three cities as keys in your
dictionary. Create a dictionary of information about each city and include the country that
the city is in, its approximate population, and one fact about the city. The keys for each
city’s dictionary should be something like country, population, and fact. Print the name of
each city and all the information you have stored about it.
Codes:
Output:
20. Favorite Foods: Create a program that shwing that a person can have more than one
favorite foods. Then print each person’s name along with their favorite foods.
Codes:
Output: