Python Programs
Python Programs
Q1. Write a program to input two numbers from the user and display their:
- Sum
- Difference
- Product
- Quotient
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print("Sum:", a + b)
print("Difference:", a - b)
print("Product:", a * b)
if b != 0:
print("Quotient:", a / b)
else:
print("Cannot divide by zero.")
Q2. A student scored 480 marks out of 600. Write a program to calculate and
print the percentage.
marks_obtained = 480
total_marks = 600
percentage = (marks_obtained / total_marks) * 100
print("Percentage:", percentage, "%")
Q3. A shirt is priced at ₹800. There’s a 20% discount on it. Calculate the amount
saved and final price.
price = 800
discount = 20 # percent
amount_saved = (discount / 100) * price
final_price = price - amount_saved
A = P * (1 + r/n) ** (n*t)
print("Final Amount after Compound Interest: ₹", round(A, 2))
Q7. Write a program that takes weight (kg) and height (m) as input and
calculates BMI using:
BMI = weight / (height * height)
weight = float(input("Enter your weight (in kg): "))
height = float(input("Enter your height (in meters): "))
Q8. Convert ₹10,000 into USD, assuming 1 USD = ₹83.5. Print the result rounded
to 2 decimal places.
inr = 10000
usd_rate = 83.5
Q9. Write a Python program to print all numbers from 50 to 100 that are
divisible by 5 and 7 using a for loop.
for num in range(50, 101):
if num % 5 == 0 and num % 7 == 0:
print(num)
Q10. Create a dictionary student_scores with names and marks of 4 students.
Add a new student to the dictionary. Display names of students who scored
more than 75.
student_scores = {
"Alice": 82,
"Bob": 67,
"Charlie": 91,
"David": 74
}
area = calculate_area(l, w)
print("Area of rectangle:", area)
Q12. Create a CSV file products.csv with 4 columns: Product, Price, Quantity,
Category. Write a program using Pandas to load the file and:
- Display the first 3 rows.
- Show the total number of rows and columns.
- Print the average price of all products.
import pandas as pd
# Load CSV
df = pd.read_csv('products.csv')
Q13. Given marks of students: [55, 65, 75, 85, 45, 90, 62, 78, 88, 72]. Create a
histogram showing the distribution of scores using bins of 10.
import matplotlib.pyplot as plt
marks = [55, 65, 75, 85, 45, 90, 62, 78, 88, 72]
Create a NumPy array of the Salary column and calculate: • Mean, median, and standard
deviation • Normalize the Performance_Score column using NumPy so values range
between 0 and 1. • Using NumPy, find the employee(s) with the highest and lowest
Experience_Years. Q. Using the statistics module, calculate: • Mode of the Experience_Years
• Variance of the Performance_Score Q. Create the following plots using Matplotlib: •
Histogram of employee ages • Boxplot of salaries across all departments • Line plot showing
Performance_Score against Employee_ID how to use saved data set in pythomn
You will typically use pandas to load a dataset from a CSV or Excel file. If your dataset is
saved as a CSV file, you can use the following code to load it:
python
Copy code
import pandas as pd
python
Copy code
df = pd.read_excel('your_dataset.xlsx') # Replace with the correct path
to
df = pd.read_csv(r'C:\Users\Lenovo\Documents\Python PG33\Employee_Dataset (1).csv')
(a) Create a NumPy array of the Salary column and calculate mean, median, and standard
deviation:
python
Copy code
salary_array = np.array(df['Salary'])
# Mean
mean_salary = np.mean(salary_array)
# Median
median_salary = np.median(salary_array)
# Standard Deviation
std_salary = np.std(salary_array)
# Min-Max normalization
performance_normalized = (performance_array - np.min(performance_array))
/ (np.max(performance_array) - np.min(performance_array))
print(performance_normalized)
# Highest Experience
max_experience = np.max(experience_array)
max_experience_employees = df[df['Experience_Years'] == max_experience]
# Lowest Experience
min_experience = np.min(experience_array)
min_experience_employees = df[df['Experience_Years'] == min_experience]
plt.boxplot(salary_data, labels=departments)
plt.title('Boxplot of Salaries across Departments')
plt.xlabel('Department')
plt.ylabel('Salary')
plt.xticks(rotation=45)
plt.grid(True)
plt.show()
Would you also like me to pack all of this nicely into one clean .ipynb (Jupyter notebook)
file so you can directly upload and run? 🚀
(Just say "yes"!)
4o
You said:
how to save this file
ChatGPT said:
Copy the code I gave you into a new Jupyter Notebook (.ipynb).
Go to File → Save and Checkpoint
or simply press Ctrl + S.
It saves automatically as a .ipynb file (a Notebook file).
Open any text editor like VS Code, Notepad++, PyCharm, or even basic Notepad.
Paste the entire code.
Save the file with a .py extension, for example:
Copy code
employee_analysis.py
While saving, select Save as type: All Files, not .txt, and make sure the filename
ends with .py.
✅ After saving:
You can run .py files from the Command Prompt by:
bash
Copy code
python filename.py