Professional Documents
Culture Documents
BSIS-1M-Muhammad Talha Munir - Assingment 3
BSIS-1M-Muhammad Talha Munir - Assingment 3
Bahawalpur
Department of
Information Security
Assignment # 3
Programming
Fundamentals
Class: BS(IS) – Semester 1
( Morning )
Course Instructor: Dr.
Shahzada Khurram
Name: Muhammad Talha
Munir
Roll no: F20BINFS1M02046
Q 1. Find the errors in the following if statements.
Result
( c)
Solution:
x=int(input(“Enter an integer value”))
x=int(x)
if (x):
sum = sum + x
else
print(“Bad input of x”)
Q 2. Write pseudocode for a program that assigns letter grades for a quiz, according to the
following table:
Score Grade
90-100 A
80-89 B
70-79 C
60-69 D
< 60 F
Result:
1. Int(input(enter a score))
2. Condition if( x>=90 and x<=100) then print(‘A’)
3. condition elif (x>=80 and x<=89) then print(‘B’)
4. condition elif (x>=70 and x<=79 )then print(‘C’)
5. condition elif (x>=60 and x<=69) then print(‘D’)
6. condition elif (x<60 )then print(‘F’)
7. else:
8. print(‘strange grade’)
Q 3. Suppose the value of b is False and the value of x is 0. What is the value of each of the
following expressions?
a) b and x == 0
True
b) b or x == 0
False
c) not b and x == 0
False
d) not b or x == 0
True
e) b and x != 0
False
f) b or x != 0
False
g) not b and x != 0
False
Q 4. Complete the following truth table by finding the truth values of the Boolean expressions for
all combinations of the Boolean inputs a, b, and c.
a) b == True
if(b)
b) b == False
if(!b)
c) b != True
if(!b)
d) b != False
if(b)
Q 6. Explain the difference between an if/elif/else sequence and nested if statements. Given of
example of each.
Def.
We can have a if...elif...else statement inside another if...elif...else statement. This is called nesting in
computer programming.
Any number of these statements can be nested inside one another. Indentation is the only way to figure
out the level of nesting. They can get confusing, so they must be avoided unless necessary.
Example:
''In this program, we check if the number is positive or negative or zero and display an appropriate
message'''
num = 3.4
# num = -4.5
Def.
Decision making is required when we want to execute a code only if a certain condition is satisfied.
Example:
'''In this program, we input a number check if the number is positive or negative or zero and display
if num >= 0:
if num == 0:
print("Zero")
else:
print("Positive number")
else:
print("Negative number")
Q 7. Write a program in Python to calculate the total expenses. Quantity and price per item are
input by the user and discount of 10% is offered if the expense is more than 5000.