PF lab 4
PF lab 4
DECISIONS
OBJECTIVE:
To get familiar with the concept of conditional statement for simple decision making.
EXERCISE:
A. Point out the errors, if any, in the following Python programs.
1. CODE:
a = 500,b,c;
if ( a >= 400 ) :
b = 300
c = 200
print( “Value is:” , b, c )
2. CODE:
&number = eval(input("Enter an integer: "))
print(type(number))
if number % 5 == 0:
print("HiFive")
else:
print("No answer")
ERROR: There are two noticable SyntaxErrors in this code:
I. A variable’s name cannot start with special characters like ‘&’.
II. There is a missing colon(:) at the end of the if statement .
CORRECTION:
3. CODE:
if score >= 60.0
grade = 'D'
elif score >= 70.0
grade = 'C'
if score >= 80.0
grade = 'B'
if score = >= 90,0
grade = 'A'
else:
grade = 'F'
ERROR: This is a SyntaxError as the if statements are missing a colon(:) at the end.
CORRECTION:There are two errors in this code:
I. The first error is a SyntaxError as the if statements are missing a colon(:) at the end.
II. The second error is a NameError as the name ‘score’ is not defined.
CORRECTION:
2. CODE:
OUTPUT:
num = 3
if num >= 0:
print("Positive or Zero")
else:
print("Negative number")
3. CODE:
OUTPUT:
age = 15
if age < 4:
price = 0
elif age < 18:
price = 1500
else:
price = 2000
print("Your admission cost is Rs " + str(price) + ".")
C. Write Python programs for the following:
1. Any integer is input through the keyboard. Write a program to find out whether it is an odd
number or even number.
2. Write a program that asks for years of service and qualification from the user and
calculates the salary as per the following table: