- Collapse Code
# Prompt user for values for each of the variables
# (b1, b2, _a, _b, _c, _d, and _e) and store said
# value into the variable (see sample output)
print()
"""
PART 1: BOOLEAN EXPRESSION PRACTICE
Place your line of code UNDERNEATH the
instruction comment. Follow the format I
provide for you here, with the expression
as part of the string literal and in parentheses
after the plus sign for concatenation
"""
# EXAMPLE
# Write an expression that is true if
# b1 and b2 are BOTH true
print ("b1 and b2 is " + str(b1 and b2) )
# Write an expression that is true if
# EITHER b1 OR b2 (or both) is true
# Write an expression that is true if
# b1 and b2 are BOTH false
# Write an expression that is true if _a
# is GREATER THAN _b
# Write an expression that is true if _c
# and _e are NOT EQUAL
print ()
######################/
#
# PART 2: BASIC IF/ELSE STATEMENTS
#
######################/
# EXAMPLE
# if b1 is true, print out: b1 is true!
if b1:
print ("b1 is true!")
# if b2 is true, print out: b2 is true!
# if at least one of b1 and b2 is true, print out:
# At least one, b1 or b2, is true!
# Otherwise, print out: b1 and b2 are BOTH false!
print ()
######################/
#
# PART 3: NESTED IF/ELSE STATEMENTS
# See example code below
#
######################/
# if _a is less than _b, print out:
# _a is less than _b
# if _a is less than _c as well, also print out:
# _a is less than _c, too!
# Otherwise, print out:
# _a may be less than _b, but it is greater than or equal to _c
#
# However, if _a is NOT less than _b, print out:
# _a is greater than or equal to _b, but we don't know its relation to c
# In addition, if _a is less than _d, print out:
# _a is less than _d
# YOUR CODE GOES HERE
"""
EXAMPLE CODE
if _d is greater than or equal to _e, print out:
_d is greater than or equal to _e
if _d is also less than or equal to _c, also print out:
_d is also less than or equal to _c
However, if _d is less than _e, print out:
_d is less than _e
In addition, if _d is greater than _b, also print out:
...but _d is greater than _b
Otherwise, also print out:
...and _d is less than or equal to _b
if _d >= _e:
print ("_d is greater than or equal to _e")
if _d <= _c:
print ("_d is also less than or equal to _c")
else:
print ("_d is less than _e")
if _d > _b:
print ("...but _d is greater than _b")
else:
print ("...and _d is less than or equal to _b")
"""
- Collapse Code
+ Expand Code
# Prompt user for values for each of the variables
# (b1, b2, _a, _b, _c, _d, and _e) and store said
# value into the variable (see sample output)
.........
Your task, then, is to follow the directions in the comments in order to make changes to the code that will result in the desired output being printed to the screen.
- Write the code to prompt the user for input and store the provided information (converted to the correct type, if needed) in variables with the given names.
- Write the print statements that print the expression itself and whether it is True or False.
- Write the simple if and if/else statements
- Write the nested if/else statements
Some of the instructions in the comments are frequently misinterpreted, so make certain that you are present in class to receive the detailed explanations that I intend to give in class!
Note that because b1 and b2 are being assigned True or False based on user input, while the other variables are also being assigned user-specified int and/or float values, the output will look different each time you run the program. To this end, I have provided multiple examples of how the output could look.
Note also that some parts of the sample output are blacked out like this: __________ This is because you are being asked to write the boolean expression twice -- once as part of the output string text and once to actually be evaluated as True or False. The blacked out portions are just to avoid giving away the answer in the sample output.
Program output examples:
- Collapse Output
What is the value of b1? True
What is the value of b2? False
What is the value of _a? 10
What is the value of _b? -29
What is the value of _c? 45
What is the value of _d? 67.0
What is the value of _e? -56.3
b1 and b2 is False
__________ is True
__________ is False
__________ is True
__________ is True
b1 is True!
At least one, b1 or b2, is True!
_a is greater than or equal to _b, but we don't know its relation to c
_a is less than _d
+ Expand Output
What is the value of b1? True
What is the value of b2? False
What is the value of _a? 10
...
- Collapse Output
What is the value of b1? False
What is the value of b2? True
What is the value of _a? 78
What is the value of _b? -34
What is the value of _c? 345
What is the value of _d? 89.4
What is the value of _e? 35.6
b1 and b2 is False
__________ is True
__________ is False
__________ is True
__________ is True
b2 is True!
At least one, b1 or b2, is True!
_a is greater than or equal to _b, but we don't know its relation to c
_a is less than _d
+ Expand Output
What is the value of b1? False
What is the value of b2? True
What is the value of _a? 78
...
- Collapse Output
What is the value of b1? False
What is the value of b2? False
What is the value of _a? 65
What is the value of _b? -345
What is the value of _c? 27
What is the value of _d? -687.5
What is the value of _e? 89.0
b1 and b2 is False
__________ is False
__________ is True
__________ is True
__________ is True
b1 and b2 are BOTH False!
_a is greater than or equal to _b, but we don't know its relation to c
+ Expand Output
What is the value of b1? False
What is the value of b2? False
What is the value of _a? 65
...
In at least 150 words, please address the following questions in memo.txt: - How did the process of creating these programs go for you?
- What were your main challenges and how did you overcome them?
- What did you learn that may be of use as you move along in this class?