Programming Fundamental in Python (1)
Programming Fundamental in Python (1)
1) Aim: - Write a Python code to input three numbers. Display the sum and
average of three numbers.
Sample Input: 64, 72, 65
Sample Output: Sum= 201
Average= 67.0
Source code: -
# Input three numbers from the user
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
num3 = float(input("Enter the third number: "))
Output of code: -
Enter the side of the square: 15
Area of the square: 225.0
Perimeter of the square: 60.0
Enter the length of the rectangle: 18
Enter the breadth of the rectangle: 12
Area of the rectangle: 216.0
Perimeter of the rectangle: 60.0
3) Aim: - Write a Python code to input the name and basic salary of
an employee. Calculate and display the name, gross salary and
net salary of the employee when:
da = 30% of basic
hra=18% of basic
pf = 12.5% of basic
gross=basic+da+hra
net=gross-pf
Source code: -
# Input the name and basic salary of the employee
name = input("Enter the employee's name: ")
basic_salary = float(input("Enter the basic salary of the employee: "))
Output of code: -
4) Aim: - A jewellery shop charges 20% making charges on gold price for
purchasing any ornament. However, the shopkeeper offers a special discount of
30% to their customers on making charges.
Write a Python code to input gold price/gm and weight of the ornament. Now,
calculate and display the following:
(a) Actual cost of the ornament
(b) Actual making charges
(c) Discount on making charges
(d) Amount to be paid by the customer
Sample Input: Gold price/gm = 5200 Weight of ornament = 10.4 gm.
Sample Output: Actual cost = ₹ 54080 Actual making charges = 10816 Discount
on making charges = 3244.8 Amount to be paid by the customer = 61651.2
Source code: -
# Input the gold price per gram and the weight of the ornament
gold_price_per_gm = float(input("Enter the gold price per gram: "))
weight_of_ornament = float(input("Enter the weight of the ornament in gm: "))
# (b) Calculate the actual making charges (20% of the actual cost)
making_charges = 0.20 * actual_cost
Output of code: -
Enter the gold price per gram: 5200
Enter the weight of the ornament in gm: 10.4
Actual cost of the ornament: ₹54080.00
Actual making charges: ₹10816.00
Discount on making charges: ₹3244.80
Amount to be paid by the customer: ₹61651.20
Output of code: -
6) Aim: - Write a Python code to input three numbers and display the smallest
number.
[Hint: Use min() function]
Sample Input: a = 58, b= 46, c= 99
Sample Output: Smallest Number = 46
Source code: -
# Input three numbers
a = int(input("Enter the first number (a): "))
b = int(input("Enter the second number (b): "))
c = int(input("Enter the third number (c): "))
Output of code: -
7) Aim: - The final velocity of a vehicle can be calculated by using the formula: v²
= u² + 2as where, u = initial velocity, v = final velocity, a = acceleration and d =
distance covered
Write a Python code to calculate and display the final velocity by taking initial
velocity, acceleration and distance covered as inputs
Source code: -
import math
Output of code: -
8) Aim: - Write a Python code to find the difference between Simple Interest (SI)
and Compound Interest (CI) taking Principal, Rate and Time as inputs.
[Hint: CI = A - P where, A=P^ * (1 + R/100) ^ T]
Source code: -
# Input Principal, Rate, and Time
P = float(input("Enter the Principal amount (P): "))
R = float(input("Enter the Rate of interest (R) in percentage: "))
T = float(input("Enter the Time period (T) in years: "))
# Calculate Simple Interest (SI)
SI = (P * R * T) / 100
Output of code: -
9) Aim: - Write a Python code to accept the number of days and display the result
after converting it into number of years, number of months and the remaining
number of days
Source code: -
# Input the number of days
total_days = int(input("Enter the number of days: "))
Output of code: -
10) Aim: - Write a Python code to enter the three sides of a scalene triangle and
calculate the area of the scalene triangle by using the formula: Area= sqrt(s(s - a)(s
- b)(s - c)) where, s = (a + b + c)/2
[Hint: The sum of any two sides must be greater third side.]
Source code: -
import math
Output of code: -
12) Aim: - Write a Python code to display three rational numbers between any two
consecutive natural numbers, taking inputs from the console.
Sample Input: 7 and 8
Sample Output: 7.25
7.5
7.75
[Hint: Rational number between m and n can be calculated as: (m+n)/2].
Source code: -
# Input two consecutive natural numbers
m = int(input("Enter the first natural number (m): "))
n = int(input("Enter the second natural number (n): "))
Output of code: -