What operator can be used in the conditional evaluation of an if statement to so that both
Fantastic news! We've Found the answer you've been seeking!
Question:
Conversely what operator is used so that either Boolean expression can be true for the compound expression to be true?
When is the short-circuit evaluation performed for an or statement?
What are the only possible values available for a Boolean variable?
What operator can be used to reverse the value of a Boolean expression?
Writing iffy statements
Write the python code for the following situations. I have highlighted variable names in bold.
Print "bad weather" if temperature is greater than 100 or less than 0.
Print "Great weather" if temperature is between 65 and 75.
Print "Class Cancelled" if severe_weather is True and class_format is "On Campus"
Print "Class as Scheduled" if class_format is not equal to "On Campus" or severe_weather is False.
Print True if variable x is greater than y and less than z. Otherwise print False.
Boolean Variables
For each of the questions in this section, read the code and indicate whether True or False is printed.
What is printed for the code below:
a = True
b = False
c = True
d = a or b or c
print(d)
What is printed for the code below:
a = True
b = True
c = False
d = a and b and c
print(d)
What is printed for the code below:
a = True
b = True
c = True
d = a and b and c
print(d)
What is printed for the code below:
a = True
b = True
c = False
d = a and b and c
print(d)
What is printed for the code below:
a = True
b = not a
print(b)
What is printed for the code below:
a = False
b = not a
print(b)
Programming Exercise
For the following exercise, you will be writing a program to calculate rewards for a book club. Serendipity booksellers has a book club that awards points t its customers based on the number of books purchased each month. The points are awarded as follows:
If a customer purchases 0 books, they earn 0 points.
If they purchase 2 books, they earn 5 points.
If they purchase 4 books, they earn 15 points.
If they purchase 6 books, they earn 30 points.
If they purchase 8 or more books, they earn 60 points.
The program should ask the user to enter the number of books that they have purchased this month and then displays the number of points awarded.
It should look something like this when run:
Copy the python code in the section below.
Python Code
Take a screenshot of tests for each point range.
Related Book For
Fundamentals Of Digital Logic With Verilog Design
ISBN: 9780073380544
3rd Edition
Authors: Stephen Brown, Zvonko Vranesic
Posted Date: