Scientific Computing
Create a file boolean.py
and save it to cs100/ch2
.
n=10
and k=20
. For each of the following boolean expressions, determine whether it evaluates to True
or False
. First, write your answer in comments. Then, verify it by writing code to print out the result of the expression.
(n == 10) and (k == 20)
(n > 10) and (k == 20)
(n > 10) or (k == 20)
not( (n > 10) and (k == 20) )
(not(n > 10)) and (not(k == 20))
(n > 10) or (k == 10 or k != 5)
(n < 20) or (k == 20)
(n <= 10) and (k < 20)
(n >= 10) and (k <= 20)
num
which is initialized to some value. Give a boolean expression for each of the following situations:
num
is between 5 and 10, inclusive.num
is greater than or equal to 0 and strictly less than 100.num
is strictly less than 100 and greater than or equal to 0, or it is equal to 200num
is a strictly positive number but not strictly larger than 150if x > 5:
print("A")
elif y < 10:
print("B")
elif x == 10:
print("C")
else:
print("D")
x=8
and y=3
?x=5
and y=11
?x=10
and y=11
?x=0
and y=5
?x
or y
that will print āCā?random
module at the top of your file. What is exactly do the following statements print? Why are the results different? Write your answer in comments.
print( random.random() )
print( random.random() )
print( random.random() )
Complete problem 2.33 on page 72 of your book.
Complete problem 2.35 on page 72 of your book.
Submit your file to Moodle.