Homework 2 - Booleans and if-elif-else
Due Date: September 19, 2023
Do not import any modules to solve any of the problems below. Only use what we have learned thus far. If you are not sure then please ask. When uploading your file, please make sure to click on the submit button once the file has finished uploading. Assignment due by 11:59 pm on the due date.
Problems
- Thus far, we have encountered the following data types:
str
- string data typeint
- integer data typefloat
- float data type
What new data type is introduced this week? What are the possible values for this new data type?
- What does the function
bool()
do? Give two explicit code examples and explain. - What are the three boolean operators? Describe what each does and include explicit code examples for each.
- What are the comparison operators? Describe what each does and include explicit code examples for each.
- For each expression below, what is the value of the expression? Explain thoroughly.
-
>>> 33 == '33'
-
>>> bool(0) != bool('')
-
>>> x = 4.3
>>> y = 0.5
>>> x < y or 2*y < x -
not (1 == '1' and 2 < 3)
-
Write a program that asks a user to input three numbers, say \(a, b, c\), and returns a message telling the user which number entered was the "smallest", which one is the "middle" number, and which one is the "largest" number. As as an example, if the user enters \(a=3\), \(b=7\), \(c=2\) then your program should print the message:
"""The smallest number entered was 2
The middle number entered was 3
The largest number entered was 7
"""On the other hand, if the user enters two numbers that are equal, for example \(a=3\), \(b=7\), \(c=3\) then your program should output:
"""The smallest number entered was 3
The largest number entered was 7
"""And if all the numbers entered are equal, for example \(a=4\), \(b=4\), \(c=4\) then your program should output:
Use only"All of the numbers entered are equal to 4"
if, elif, else
statements; do not use lists to store your numbers and do not use functions not discussed in Chapters 1-2.You work for an airline and you are asked to create a ticket reservation system. Your airline services only two airports on the east coast, John F. Kennedy airport (JFK) and Logan International Airport (BOS). On the west coast, your airline only services Los Angeles airport (LAX). Everyday there are 5 outbound flights from the east coast to LAX as follows:
- Three flights out of JFK leave in the morning:
- Lay over in Chicago with total travel time of 8 hours.
- Lay over in Atlanta with total travel time of 9 hours.
- Lay over in Kansas City with total travel time of 7 hours.
- Two flights out of BOS leave in the afternoon:
- Lay over in Houston with total travel time of 10 hours.
- Lay over in Nashville with total travel time of 8 hours.
If the passenger says no then display a message to the passenger of the type:"Please have your credit card ready to purchase your flight."
Be creative!"Would you like to start again with a new reservation?"
- Three flights out of JFK leave in the morning: