Week 2: Python Programs Student Name: Manish M SRN: PES1UG20ME172
Week 2: Python Programs Student Name: Manish M SRN: PES1UG20ME172
Week 2: Python Programs Student Name: Manish M SRN: PES1UG20ME172
Progra Create a program that has two parameters namely name and their age. Print out a
m1
message addressed to them that tells them the year that they will turn 100 years old.
Algorithm:
#input:name and age
#claculation:100+2021-age
#output:the year in which the age is going to be 100
Program with appropriate Comments:
name=input("enter ur name")
x=int(input("enter ur age"))
year=100+2021-x
print("the year when ",name,"is going to be 100 years old is",year)
Out Put Screen shot:
Progra N students take K apples and distribute them among each other evenly. The remaining
m2
(the undivisible) part remains in the basket. How many apples will each single student
get? How many apples will remain in the basket?The program reads the
numbers N and K. It should print the two answers for the questions above.
Algorithm:
#input: no. of students and no. of apples
#calculation: n//k, n%k
#output: no. of apples each student gets, no. of apples remaining in the basket
x=n//k
y=n%k
print("the no. of apples each student gets is",x)
print("the no. of apples left in the basket is",y)
Algorithm:
#input:coordinates of the two points
#calculation:((a-b)^2+(c-d)^2)^0.5
#output:distance b/w two points
import math
a=int(input("enter the x coordinate of the first point"))
c=int(input("enter the y coordinate of the first point"))
b=int(input("enter the x coordinate of the second point"))
d=int(input("enter the y coordinate of the second point"))
x=((a-b)**2+(c-d)**2)
y=math.pow(x,0.5)
print("distance b/w the two points is",y)
Progra Given two timestamps of the same day: a number of hours, minutes and seconds for
m4
both of the timestamps. The moment of the first timestamp happened before the
moment of the second one. Calculate how many seconds passed between them.
Algorithm:
#input=initial time and final time
#calculation=conversion of hours and minutes to second and difference of it.
#output=seconds b\w the time
x=((d-a)*3600)+((e-b)*60)+(f-c)
Progra Given a 4-digit integer number, display the individual digits & also compute the sum of
m5
digits.
Algorithm:
#input=for digit no.
#calculation=addition of each digit
#output=sum of each digit
Algorithm:
#input=two digits
#output=swaped value for the given variables
Progra Program to
m7
a) Convert temperature in celsius to fahrenheit
b) Convert temperature in fahrenheit to celsius
Algorithm:
#input=temperature in celcius
#calculation=(celcius*(9/5))+32
#output=temperature in farenheit
#input=temperature in farenheit
#calculation=(farenheit-32)*(5/9)
#output=temperature in celcius
Progra Given the distance between 2 cities in kilometers. Write a Python program convert it
m8
into meters, centimeters, feet and inches and display the result.
Algorithm:
Progra A school decided to replace the desks in three classrooms. Each desk sits two students.
m9
Given the number of students in each class, print the smallest possible number of
desks that can be purchased.The program should read three integers: the number of
students in each of the three classes, a, b and c respectively.In the first test there are
three groups. The first group has 20 students and thus needs 10 desks. The second
group has 21 students, so they can get by with no fewer than 11 desks. 11 desks is also
enough for the third group of 22 students. So we need 32 desks in total.
Algorithm:
#input=no. of students
#calculation=dividing the benches b\w students
#output=no. of benches needed
Program with appropriate Comments:
a=int(input("no. of students in class 1="))
b=int(input("no. of students in class 2="))
c=int(input("no. of students in class 3="))
q=(a//2)+(a%2)
w=(b//2)+(b%2)
e=(c//2)+(c%2)
x=q+w+e
print("the total no. of benches needed is ",x)
print("no. of benches requiered in class 1=",q,"class 2=",w,"class 3=",e)
Progra Given the integer N - the number of seconds that is passed since midnight - how many
m 10
full hours and full minutes are passed since midnight? The program should print two
numbers: the number of hours (between 0 and 23) and the number of minutes
(between 0 and 1339). For example, if N = 3900, then 3900 seconds have passed since
midnight. Therefore, the time now is 1:05am. So the program should print 1 65 - 1 full
hour is passed since midnight, 65 full minutes passed since midnight.
Algorithm:
#input=number of seconds passed since midnight
#calculation=conversion of second to minutes and hours
#output=time in hours and minitues
Program with appropriate Comments:
n=int(input("enter the second passed since midnight"))
x=n//3600
y=(n%3600)//60
z=(n%3600)%60
print("the current time is",x,":",y,":",z)
print("hours passed is",x,",minutes passed",y,",seconds passed",z)
Out Put Screen shot: