VITyarthi Python Essentials Module 4 Challenging Task Solution

Challenging Task-Peer Assessment 1

Profit calculation Using “Operators”
Mr. Rama buys a 2BHK luxury apartment in Bhopal for the cost of Rs.A and he has gone for
interior decorations with Rs.B cost. Luckily in his territory the government has announced a
Special Economic Zone (SEZ). The demand for the flats in that area was boosted by the white
collar & golden collar professionals. If he sells the flat for Rs.Z, what is his profit in
percentage? Write a Python program to compute the profit in percentage?

Input format : Three integers separated by space.

Output format : The profit is:

 Sample Input: Enter cost, interior decoration, selling price: 1000000 10000 5000000 

Sample Output: The profit is: 395.05

Solution

				
					cost, decoration, selling_price = input("Enter cost, interior decoration, selling price: ").split()

cost = int(cost)
decoration = int(decoration)
selling_price = int(selling_price)

profit = (selling_price - (cost + decoration)) / cost
profit_percentage = profit * 100

print("The profit is: {:.2f}%".format(profit_percentage))


				
			

Challenging Task-Peer Assessment 2

Mr. Ashok Goel has spent ‘n’ units of effort in preparing for UPSC examination in a year.Can you calculate using a Python program how many hours, minutes and seconds he has spent on attaining success.

Input format : One integer 

Output format :
Hours:
Minutes:
Seconds:

Sample Input: 45678

Sample Output: 

Hours: 12

Minutes: 41

Seconds: 18

Solution

				
					n = 45678

#converting units of effort to seconds
seconds = n*60

#calculating hours, minutes and seconds
hours = seconds // 3600
minutes = (seconds % 3600) // 60
seconds = (seconds % 3600) % 60

print("Hours:", hours, "Minutes:", minutes, "Seconds:", seconds)

				
			

Challenging Task-Peer Assessment 3

A car has travelled D kilometers in T hours of time. What is the speed of the car in km/hr? Write a python program to demonstrate.

Input format: Enter integers for distance and time

Output format: The speed of the car in Km/hr is:

Sample Input: 

56 

4

Sample Output: 

14.0

Solution

				
					distance = int(input("Enter the distance traveled (in km): "))
time = int(input("Enter the time taken (in hours): "))

speed = distance / time

print("The speed of the car in Km/hr is:", speed)




				
			

Challenging Task-Peer Assessment 4

The hypotenuse is the longest side of a right angled triangle. Using Pythagoras’s theorem, Calculate the third side and also the area of the right triangle.

Input format: Enter two integers for width and height

Output format: The third of the triangle is:

Area of the right angled triangle is: 

Sample Input: 

Enter width: 7 

Enter height: 8

Sample Output: The third of the triangle is:10.63 Area of the right angled triangle is:28.0

Solution

				
					import math

width = int(input("Enter width: "))
height = int(input("Enter height: "))

hypotenuse = math.sqrt(width**2 + height**2)
area = 0.5 * width * height

print("The third of the triangle is: %.2f" % hypotenuse)
print("Area of the right angled triangle is: %.1f" % area)



				
			

If you find anything wrong in this Solution, feel free to reach us in the comment section.

Sharing Is Caring:

Leave a Comment