Module 3 Conditional Statements and Loops
Module 3 Conditional Statements and Loops
Conditional Statements
1. Take a variable ‘age’ which is of positive value and check the following:
a. If age is less than 10, print “Children”.
b. If age is more than 60 , print ‘senior citizens’
c. If it is in between 10 and 60, print ‘normal citizen’
if Person_Age<=10:
print('Children')
elif Person_Age>=60:
print('senior citizens')
print('normal citizen')
else:
print('enter age')
2. Find the final train ticket price with the following conditions.
a. If male and sr.citizen, 70% of fare is applicable
b. If female and sr.citizen, 50% of fare is applicable.
c. If female and normal citizen, 70% of fare is applicable
d. If male and normal citizen, 100% of fare is applicable
[Hint: First check for the gender, then calculate the fare based on age factor.. For both
Male and Female ,consider them as sr.citizens if their age >=60]
Tkt_price=1000
disc_senior_male=(30/100)*1000
Senior_Male_Fare=Tkt_price-disc_senior_male
disc_senior_female=(50/100)*1000
Senior_Female_Fare=Tkt_price-disc_senior_female
disc_female=(30/100)*1000
Female_Fare=Tkt_price-disc_female
print('You are a Male senior citizen and only 70% fare is applicable')
print('You are a Female senior citizen and only 50% fare is applicable')
print('You are a Female Normal citizen and only 70% fare is applicable')
else:
print('You are a Male Normal citizen and 100% fare is applicable, No Discount !')
3. Check whether the given number is positive and divisible by 5 or not.
else:
Conditional Statements
3. Consider a list1 [3,4,5,6,7,8]. Create a new list2 such that Add 10 to the even number
and multiply with 5 if it is odd number in the list1..
4. Write a simple user defined function that greets a person in such a way that :
i) It should accept both name of person and message you want to deliver.
ii) If no message is provided, it should greet a default message ‘How are you’
seq_numbers=int(input('Enter a Number:-'))
i=0
for i in range(seq_numbers,100):
print(i)
i=i+1
list_A=[0,1,2,3,4,5,6,7,8,9]
list_B=['zero','one','Two','Three','Four','Five','six','seven','eight','nine']
dictionary=dict(zip(list_A,list_B))
list_a=[3,4,5,6,7,8]
b=list_a.split()
print(b)
def greet(Name):
print('Hello',Name)
greet('Ram, How are You')