Py QB
Py QB
# 1. Currency Converter
def rupees_to_dollar():
try:
except ValueError:
print("Invalid input!")
# 2. Gross Salary
def calculate_gross_salary():
try:
da = 0.7 * bs
ta = 0.3 * bs
hra = 0.1 * bs
gross_salary = bs + da + ta + hra
except ValueError:
print("Invalid input!")
# 3. Simple Interest
def simple_interest():
try:
si = (p * r * t) / 100
print("Invalid input!")
# 4. Arithmetic Operations
def arithmetic_operations():
try:
print("Addition:", a + b)
print("Subtraction:", a - b)
print("Multiplication:", a * b)
try:
print("Division:", a / b)
except ZeroDivisionError:
except ValueError:
print("Invalid input!")
# 5. Area Calculator
def area_calculator():
try:
if ch == 1:
print("Area:", side**2)
elif ch == 2:
l = float(input("Length: "))
b = float(input("Breadth: "))
print("Area:", l * b)
elif ch == 3:
b = float(input("Base: "))
h = float(input("Height: "))
print("Area:", 0.5 * b * h)
else:
print("Invalid choice.")
except ValueError:
print("Invalid input!")
# 6. Task List
tasks = ['Go to the office', 'Pay Bills', 'Visit doctor', 'Cook the food', 'Arrange wardrobe', 'Swimming
class']
def manage_tasks():
tasks.append('New Task')
tasks.remove('Pay Bills')
print("Tasks:", tasks)
# 7. List Operations
def list_operations():
nums = []
for _ in range(5):
print("List:", nums)
print("Sum:", sum(nums))
print("Max:", max(nums))
# 8. Set Operations
def set_operations():
# 9. Dictionary Operations
def manage_students():
students = {
students["2"]["grade"] = 95
for k, v in sorted_students:
print(v['name'], v['grade'])
def check_character():
if ch.isdigit():
print("Digit")
elif ch.islower():
print("Lowercase")
elif ch.isupper():
print("Uppercase")
else:
print("Special Character")
def multiplication_table():
try:
except ValueError:
print("Invalid input!")
class Student:
def get_roll_no(self):
return self.__roll_no
def get_name(self):
return self.__name
def get_marks(self):
return self.__marks
def display(self):
class Fees(Student):
self.fees = fees
def submit_fees(self):
def generate_receipt(self):
class Result(Student):
self.grade = self.calculate_grade()
def calculate_grade(self):
marks = self.get_marks()
return "A"
return "B"
return "C"
else:
return "D"
def display_result(self):
def sort_students(students):
for s in students:
s.display()
if __name__ == "__main__":
s1.display()
s1.submit_fees()
s1.generate_receipt()
r1.display_result()
r2.display_result()
sort_students(student_list)
q3
Here's a complete and Python IDLE-compatible set of scripts for all tasks in Q3, including NumPy,
Pandas, and Matplotlib.
# a. Create arrays
print("1D:", arr1D)
print("2D:\n", arr2D)
print("3D:\n", arr3D)
# Reshaping
# b. Element-wise operations
A = np.array([1, 2, 3])
B = np.array([4, 5, 6])
print("Add:", A + B)
print("Subtract:", A - B)
print("Multiply:", A * B)
print("Divide:", A / B)
print("Mean:", np.mean(data))
print("Median:", np.median(data))
print("Variance:", np.var(data))
Make sure you download Iris.csv from the link and save it in the same folder as this script.
import pandas as pd
# Load dataset
df = pd.read_csv("Iris.csv")
# a. First 8 rows
# b. Column names
df.fillna(df.mean(numeric_only=True), inplace=True)
df.dropna(inplace=True)
# e. Group by species
grouped = df.groupby("Species")
Make sure you download Toyota.csv from the link and save it in the same folder as this script.
import pandas as pd
# Load dataset
df = pd.read_csv("Toyota.csv")
plt.title("Price vs Age")
plt.xlabel("Age")
plt.ylabel("Price")
plt.grid(True)
plt.show()
# b. Histogram: KM Driven
plt.xlabel("Kilometers Driven")
plt.ylabel("Frequency")
plt.show()
fuel_counts = df['FuelType'].value_counts()
fuel_counts.plot(kind='bar', color='orange')
plt.xlabel("Fuel Type")
plt.ylabel("Number of Cars")
plt.show()
fuel_counts.plot(kind='pie', autopct='%1.1f%%')
plt.ylabel("")
plt.show()
df.boxplot(column='Price', by='FuelType')
plt.xlabel("Fuel Type")
plt.ylabel("Price")
plt.show()
How to Run:
2. Save these scripts as .py files and run them using F5 in Python IDLE.