1.
What do these expressions evaluate to?
3 == 3
3 != 3
3 >= 4
not (3 < 4)
Solution.
- True
- False
- False
- False
3 == 3
3 != 3
3 >= 4
not (3 < 4)
num1
and num2
, which of the following would mean that both num1
and num2
are positive integers?(num1 == num2)
(num1 == num2) or (num1 > 0)
num1
is greater than 0.(num1 == num2) and (num1 > 0)
num1
is equal to num2
and num1
is greater than 0, then both values must be positive.(num1 == num2) and (num1 < 0)
a
is equal to b
or when a
is equal to 5
?a == b == 5
a = b or a = 5
==
to test for equality.a == b or a == 5
a
is equal to b
or a
is equal to 5.a = b and a = 5
==
to test for equality.a == b and a = 5
a
and b
both equal 5.x = 3 if (x > 2): x = x * 2; if (x > 4): x = 0; print(x)
x
will always equal 0 after this code executes for any value of x
x
was set to 1 originally, then it would still equal 1.x
is greater than 2, the value in x
will be doubled after this code executesx
is greater than 2? Note: these are separate if
statements.x
is greater than 2, x
will equal 0 after this code ex
ecutesx
is greater than 2, it will be set to 0.if
statement?if (x = y):
if
statement shouldn’t contain an assignment operator.if (x == y):
if !(x is not y):
if x = y:
if
statement shouldn’t contain an assignment operator.if x == y:
5 exponentiated to the 4th power
is greater than y
and less than or equal to z
?z >= 5**4 > y
5**4 > y and (5**4 < z or 5**4 == z)
and
operator comes before the or
operator in operator precedence.5**4 > y and <= z
5**4 > y and 5**4 < z or 5**4 == z
and
operator comes before the or
operator in operator precedence.5**4 > y and z >= 5**4
z >= 5**4
is the same as 5**4 <= z
.not
operator. (This exercise requires the material from Subsection 4.5.2)a > b
a >= b
a >= 18 and day == 3
a >= 18 or day != 3
a <= b
a < b
a < 18 or day != 3
a < 18 and day == 3
Mark | Grade |
---|---|
>= 90 | A |
[80-90) | B |
[70-80) | C |
[60-70) | D |
< 60 | F |
mark = float(input("Enter mark:"))
if mark >= 90:
grade = "A"
elif mark >= 80:
grade = "B"
elif mark >= 70:
grade = "C"
elif mark >= 60:
grade = "D"
else:
grade = "F"
print("Your grade is", grade)
a
, b
, and c
1 where c
is always the longest side. It will print Yes
if the triangle is right-angled, or No
otherwise.x
is equal or close enough to y
, they would probably code it up asif abs(x - y) < 0.001: # if x is approximately equal to y
...
a
, b
, and c
:date_of_easter
will give the day in March when Easter occurs. If this value is greater than 31, then the day is in April, and you must subtract 31 from the date_of_easter
variable.year = int(input("Please enter a year"))
if year >= 1900 and year <= 2099:
a = year % 19
b = year % 4
c = year % 7
d = (19 * a + 24) % 30
e = (2 * b + 4 * c + 6 * d + 5) % 7
date_of_easter = 22 + d + e
if year == 1954 or year == 2981 or year == 2049 or year == 2076:
date_of_easter = date_of_easter - 7
if date_of_easter > 31:
print("April", date_of_easter - 31)
else:
print("March", date_of_easter)
else:
print("ERROR...year out of range")