Conditional Statements Assignment
Conditional Statements Assignment
a, b = 12, 5
if a + b:
print('True')
else:
print('False')
2) Given the nested if-else structure below, what will be the value of x after code execution
completes
x = 0
a = 0
b = -5
if a > 0:
if b < 0:
x = x + 5
elif a > 5:
x = x + 4
else:
x = x + 3
else:
x = x + 2
print(x)
Assignment on If Condition’s:
Ans:Output will be 2
3) Given the nested if-else below, what will be the value x when the code executed
successfully
x = 0
a = 5
b = 5
if a > 0:
if b < 0:
x = x + 5
elif a > 5:
x = x + 4
else:
x = x + 3
else:
x = x + 2
print(x)
Ans:Output is 3
f. Above 80 - A
Ask user to enter marks and print the corresponding grade.
Ans:
Marks = int(input())
if int(Marks) <25:
print ("The grade is F")
elif int(Marks) in range(25, 46):
print ("The grade is E")
elif int(Marks) in range(45, 51):
print ("The grade is D")
elif int(Marks) in range(50, 61):
print ("The grade is C")
elif int(Marks) in range(60, 81):
print ("The grade is B")
else:
print ("The grade is A")
5) A shop will give discount of 10% if the cost of purchased quantity is more than 1000.
Ask user for quantity
Suppose, one unit will cost 100.
Judge and print total cost for user.
Ans:
Enter_Quantity=int(input())
cost=100
tc=Enter_Quantity*cost
t=tc*10/100
d=tc-t
if tc>1000:
print("Total cost along with discount",d)
else:
Assignment on If Condition’s:
print("Total cost",tc)
7) Write a Python program that accepts a string and calculate the number of digits and letters.
Sample Data : Python 3.2
Expected Output :
Letters 6
Digits 2
vowels=('a','e','i','o','u')
if Enteralphabet in vowels:
print(Enteralphabet,"is vowel")
else:
print(Enteralphabet,"is consonant")
if x == y == z:
print("Equilateral triangle")
elif x==y or y==z or z==x:
print("isosceles triangle")
else:
print("Scalene triangle")
Assignment on If Condition’s:
10) Write an If elif else condition for finding the largest number in 3 numbers.
Ans: num1 = 10
num2 = 14
num3 = 12