Python Chapter 4.2
Python Chapter 4.2
else:
Statement 2
a=4
b=4
if a<b:
print("boo !!")
print("end of conditional code")
print("end of program")
a=input("enter a word")
b="z"
c=a[0]
if c==b:
print("the word begins with ",b)
else:
print("the word does not begin with ",b)
Example 1 Example 2
if x==10: if x==10:
print("x is 10")
print("x is 10")
print("this is ok too")
else:
else:
print("x is not 10")
print("x is not 10")
▪ Read 3 tests. Compute the Average of three tests. If the Average is 60 and above display a passing message, otherwise
display the failing message.
▪ Reads a package ID and its Weight, print the package ID followed by “CLASS1” if the package weighs less than 32
ounces and “CLASS 2” if otherwise.
if (length <1):
cost=0.46
else:
cost=0.46+(length-1)*0.3
print("The cost is ",cost)
** if length is 3
Assume input is 20, 15