There are two modes when a cell is highlighted.
x
which represents the standing of an athlete at an Olympics event.¶
if grade >= 90:
print("You got an A!")
if grade >= 80:
print("You got a B!")
if grade >= 70:
print("You got a C!")
if grade >= 60:
print("You got a D!")
if grade >= 50:
print("You got an F!")
if i < j:
if j < k:
i = j
else:
j = k
else:
if j > k:
j = i
else:
i = k
print("i =", i, " j =", j, " k =", k)
(a) i = 3,j = 5,and k = 7
(b) i = 3,j = 7,and k = 5
(c) i = 5,j = 3,and k = 7
and
, or
and not
. The not
operator has the highest precedence and should be evaluated first. Then evaluate and
before or
.¶In the following, note that evaluating or
before and
in the following gives a different and incorrect answer.
What is the value of b
?
x = 2
y = 4
z = 5
b = z > 2 or x > 3 and y < 3
Test your code!:
x = int(input("Enter a positive integer. "))
# This is a comment. fill out your code below.
y
in the following? Try it first then run the code to check your answer.¶x = 30
y = "a" if x > 15 else "b"
x = 15
y = "a" if x > 15 else "b"
x = 10
y = "a" if x > 15 else "b" if x >=11 else "c"
x = 12
y = "a" if x > 15 else "b" if x >=11 else "c"
x = 35
y = "a" if x > 15 else "b" if x >=11 else "c"
y
represents a year. A leap year is a year that is divisible by 4 and not by 100 unless it is divisible by 400. For example, 4, 2008, and 1600 are leap years but not 1700. Write a segment of code that determines whether y
is a leap year. Do it in two ways: 1) Use if/elif/else statements. 2) Use only boolean logical operators and
, or
and not
.¶y
.¶# method 1, use if/elif/else
y = 1324
is leap
# method 2, use boolean operators and, or and not
# fill in the boolean expression for isLeap below
y = 2400
isLeap =
print(isLeap)
True