0% found this document useful (0 votes)
10 views10 pages

Minor Project 1 Srija Majilya

The document contains a series of Python programming exercises covering various topics such as printing formatted strings, temperature conversion, number swapping, Euclidean distance calculation, simple interest, and more. Each exercise includes a code snippet that demonstrates the solution to the problem. Additionally, there are problems related to salary calculations, triangle validation, profit/loss assessment, unit conversions, Fibonacci series, factorials, number reversal, and summation with conditions.

Uploaded by

epsilonnull8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views10 pages

Minor Project 1 Srija Majilya

The document contains a series of Python programming exercises covering various topics such as printing formatted strings, temperature conversion, number swapping, Euclidean distance calculation, simple interest, and more. Each exercise includes a code snippet that demonstrates the solution to the problem. Additionally, there are problems related to salary calculations, triangle validation, profit/loss assessment, unit conversions, Fibonacci series, factorials, number reversal, and summation with conditions.

Uploaded by

epsilonnull8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

### *Q1: Print the given strings in the specified format*

python

print("Data", "Science", "Mentorship", "Program", "started", "By", "Wayspire", sep="-")

---

### *Q2: Convert Celsius to Fahrenheit*

python

celsius = float(input("Enter temperature in Celsius: "))

fahrenheit = (celsius * 9/5) + 32

print(f"Temperature in Fahrenheit: {fahrenheit}")

---

### *Q3: Swap two numbers without using special Python syntax*

python

a = int(input("Enter first number: "))

b = int(input("Enter second number: "))

temp = a

a=b

b = temp

print(f"After swapping: First Number = {a}, Second Number = {b}")


### *Q4: Find Euclidean distance between two coordinates*

python

import math

x1, y1 = map(float, input("Enter first coordinate (x1 y1): ").split())

x2, y2 = map(float, input("Enter second coordinate (x2 y2): ").split())

distance = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)

print(f"Euclidean Distance: {distance}")

---

### *Q5: Calculate Simple Interest*

python

p = float(input("Enter Principal amount: "))

r = float(input("Enter Rate of Interest: "))

t = float(input("Enter Time in years: "))

si = (p * r * t) / 100

print(f"Simple Interest: {si}")

---
### *Q6: Find the number of dogs and chickens from heads and legs count*

python

heads = int(input("Enter total number of heads: "))

legs = int(input("Enter total number of legs: "))

dogs = (legs - 2 * heads) // 2

chickens = heads - dogs

print(f"Dogs: {dogs}, Chickens: {chickens}")

---

### *Q7: Sum of squares of first N natural numbers*

python

n = int(input("Enter a number: "))

sum_squares = (n * (n + 1) * (2 * n + 1)) // 6

print(f"Sum of squares: {sum_squares}")

---
### *Q8: Find the Nth term of an Arithmetic Series*

python

a1 = int(input("Enter first term: "))

a2 = int(input("Enter second term: "))

n = int(input("Enter N: "))

d = a2 - a1

nth_term = a1 + (n - 1) * d

print(f"The {n}th term is: {nth_term}")

---

### *Q9: Sum of two fractions*

python

from fractions import Fraction

num1, den1 = map(int, input("Enter first fraction (numerator denominator): ").split())

num2, den2 = map(int, input("Enter second fraction (numerator denominator): ").split())

sum_fraction = Fraction(num1, den1) + Fraction(num2, den2)

print(f"Sum of fractions: {sum_fraction}")

---
### *Q10: Find how many glasses of milk can be obtained*

python

tank_volume = 20 * 20 * 20

glass_volume = 3.14 * (1 ** 2) * 3

num_glasses = tank_volume // glass_volume

print(f"Number of glasses of milk: {int(num_glasses)}")

---
### *Problem 1: Calculate in-hand salary after deductions*

python

salary = float(input("Enter CTC in lakhs: ")) * 100000

hra = 0.10 * salary

da = 0.05 * salary

pf = 0.03 * salary

tax = 0

if salary > 2000000:

tax = 0.30 * salary

elif salary > 1000000:

tax = 0.20 * salary

elif salary > 500000:

tax = 0.10 * salary

in_hand_salary = salary - (hra + da + pf + tax)

print(f"In-hand monthly salary: {in_hand_salary / 12}")

---
### *Problem 2: Check if three angles form a triangle*

python

a, b, c = map(int, input("Enter three angles: ").split())

if a + b + c == 180:

print("Forms a triangle")

else:

print("Does not form a triangle")

---

### *Problem 3: Profit or Loss calculation*

python

cp = float(input("Enter Cost Price: "))

sp = float(input("Enter Selling Price: "))

if sp > cp:

print(f"Profit of {sp - cp}")

elif cp > sp:

print(f"Loss of {cp - sp}")

else:

print("No Profit, No Loss")

---
### *Problem 4: Menu-driven unit conversion program*

python

while True:

print("1. cm to ft\n2. km to miles\n3. USD to INR\n4. Exit")

choice = int(input("Enter choice: "))

if choice == 1:

cm = float(input("Enter cm: "))

print(f"{cm} cm = {cm / 30.48} ft")

elif choice == 2:

km = float(input("Enter km: "))

print(f"{km} km = {km * 0.621371} miles")

elif choice == 3:

usd = float(input("Enter USD: "))

print(f"{usd} USD = {usd * 83} INR") # Approximate exchange rate

elif choice == 4:

break

else:

print("Invalid choice")

---### *Problem 5: Fibonacci series up to 10 terms*

python

a, b = 0, 1

for _ in range(10):

print(a, end=" ")

a, b = b, a + b
### *Problem 6: Factorial of a number*

python

n = int(input("Enter a number: "))

fact = 1

for i in range(1, n + 1):

fact *= i

print(f"Factorial: {fact}")

---

### *Problem 7: Reverse a number*

python

num = int(input("Enter a number: "))

print(f"Reversed Number: {str(num)[::-1]}")

---
### *Problem 8: Sum of numbers from 1 to N, skipping multiples of 5, stopping if sum > 300*

python

n = int(input("Enter N: "))

sum_nums = 0

i=1

while i <= n and sum_nums <= 300:

if i % 5 != 0:

sum_nums += i

i += 1

print(f"Final Sum: {sum_nums}")

---

### *Problem 9: Keep accepting numbers until 0, then display sum and average*

python

nums = []

while (n := int(input("Enter a number (0 to stop): "))) != 0:

nums.append(n)

print(f"Sum: {sum(nums)}, Average: {sum(nums) / len(nums) if nums else 0}")

You might also like