Python Assingnment 2
Python Assingnment 2
Roll no – 39
Section – S8
Q1. In a bus, a total of X passengers were travelling. Passengers can be children aged less
than 12 years, senior citizens (above 65), or normal citizens. The ticket fare is categorised
as follows:
i. For normal citizens, it is Rs. xyz.
ii. For children, it is 50% less than what normal citizens fare.
iii. For senior citizens, it is 30% less than what normal citizens fare.
Calculate the total bus fare for the passenger given the age of the passenger.
b. Devise a solution and represent the same using flowchart and pseudocode.
Ans. Algorithm –
Flowchart –
c. Develop a program to calculate the total bus fare for the passenger given the age of
the passenger.
Ans. Code-
Output –
Q2. In the library system, the duration for returning books is ten days. If books are returned by the
students within the given duration have no charges. The book returned after the duration will be
fined Rs. Z per day. The book returned after the 20 days of the duration will be accounted for at Rs 3
times more than Z (3 x Z) per day. Accept the duration, the student having the book and calculate the
total amount paid to the library by the student. Identify the inputs required to solve the problem.
Ans. The input required are number of days in returning the book (n) and per day charge of late
returning the book (z).
a. Devise a solution and represent the same using flowchart and pseudocode.
Ans. Algorithm –
Flowchart –
b. Develop a program to calculate the total amount paid to the library by the student.
Ans. Code –
c. Test the program for the following: A student borrowed three books from the library on
February 23, 2023, and the due date is March 4, 2023. He has returned one book within the
duration. The second book was returned five days after the duration period. The third
returned after 30 days of the duration period.
Assume the population of a city consists of X persons of different age groups. X includes both
males and females. The department can obtain peoples date of birth from the corporation from
which the age can be calculated. (Note: Consider X to be less than or equal to 6)
Assume the election commission of India wants to count the eligible male and female voters
separately for a constituency while preparing for the forthcoming election.
Also, the public welfare department at the same time announces that the Aadhar card has to be
renewed when the kid reaches the age 5 and the biometrics needs to be updated again when
they attain the age of 15 years.
b. Devise a solution and represent the same using flowchart and pseudocode.
Ans. Algorithm –
Flowchart –
c. Develop a program to compute the age of every person. Apply the conditional construct
to check whether the person is eligible to vote and also count the number of female and
male voters and display the same.
Ans. Code-
#Problem 3: checking the eligibility of person to vote
#Input:gender and birthyear of 5 persons.
#Output:number of female and male voter and number of aadhar card
renewed.
#second person
print ("now for second person")
p2=int(input('enter 1 for M and 2 for female '))
ap2=int(input('enter the birthyear of person2 '))
ageperson2=Y-ap2
print('the age of person2 is ',ageperson2)
if (p2==1 and ageperson2>=18):
male=male+1
print('person2 is male and eligible to vote')
if (ageperson2<18 and ageperson2>=5):
print ('you are not eligible to vote and biometric needs to be
updated')
if (ageperson2<=5):
R=R+1
print('aadhar card has to be renewed')
elif (p2==2 and ageperson2>=18):
female=female+1
print('person2 is female and eligible to vote')
#third person
print ('now for the third person')
p3=int(input('enter 1 for M and 2 for female '))
ap3=int(input('enter the birthyear of person3 '))
ageperson3=Y-ap3
print('the age of person3 is ',ageperson3)
if (p3==1 and ageperson3>=18):
male=male+1
print('person3 is male and eligible to vote')
if (ageperson3<18 and ageperson3>=5):
print('you are not eligible to vote and biometric needs to be
updated ')
if (ageperson3<=5):
R=R+1
print('aadhar card has to be renewed')
elif (p3==2 and ageperson3>=18):
female=female+1
print('person3 is female and eligible to vote')
#fourth person
print ('now for the fourth person')
p4=int(input('enter 1 for M and 2 for female '))
ap4=int(input('enter the birthyear of person4 '))
ageperson4=Y-ap4
print('the age of person4 is ',ageperson4)
if (p4==1 and ageperson4>=18):
male=male+1
print('person4 is male and eligible to vote')
if (ageperson4<18 and ageperson4>=5):
print('you are not eligible to vote and biometric needs to be
updated ')
if (ageperson4<=5):
R=R+1
print('aadhar card has to be renewed')
elif (p4==2 and ageperson4>=18):
female=female+1
print('person4 is female and eligible to vote')
#fifth person
print ('now for the fifth person')
p5=int(input('enter 1 for M and 2 for female '))
ap5=int(input('enter the birthyear of person5 '))
ageperson5=Y-ap5
print('the age of person5 is ',ageperson5)
if (p5==1 and ageperson5>=18):
male=male+1
print('person5 is male and eligible to vote')
if (ageperson5<18 and ageperson5>=5):
print('you are not eligible to vote and biometric needs to be
updated ')
if (ageperson5<=5):
R=R+1
print('aadhar card has to be renewed')
elif (p5==2 and ageperson5>=18):
female=female+1
print('person5 is female and eligible to vote')
d. Extend Qn.3.c to display whether the Aadhar card has to be renewed or not after
computing the age. Also, count the number of persons need to renew the card.
Ans. Output –
Learning outcome –
● I learn how to code python programs using conditional statements to solve problems.