0% found this document useful (0 votes)
13 views

Assignment Question for Class 10

Class 10 ai

Uploaded by

anamikasanjoy8
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Assignment Question for Class 10

Class 10 ai

Uploaded by

anamikasanjoy8
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Assignment Question

1. Write a program to convert the month name to a number of days.

def month_to_days(month):
month = month.lower() # Convert the input to lowercase to handle case-insensitive input
days_in_month = {
"january": 31,
"february": 28, # Assuming a non-leap year
"march": 31,
"april": 30,
"may": 31,
"june": 30,
"july": 31,
"august": 31,
"september": 30,
"october": 31,
"november": 30,
"december": 31
}

return days_in_month.get(month, "Invalid month name")

month_name = input("Enter a month name: ")


print(f"{month_name.capitalize()} has {month_to_days(month_name)} days.")

2. Write a program to find sum of squares of first n natural numbers where n is provided by
user.

def square sum(n):

sm = 0

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

sm = sm + (i * i)

return sm

n = int(input(“Enter a number”))

print(squaresum(n)
3. A company decided to give bonus of 5% to an employee if his/her year of service
is more than 5 years. Write a Python program to ask the user for their salary and
year of service and print the net bonus amount.

salary = float(input("Enter your salary: "))

years_of_service = int(input("Enter your years of service: "))

if years_of_service > 5:
bonus = salary * 0.05 # 5% bonus
else:
bonus = 0 # No bonus for less than or equal to 5 years of service
if bonus > 0:
print("Congratulations! You have earned a bonus of: ",bonus)
else:
print("Sorry, you are not eligible for a bonus.")

4. Create a list of all students in your class and sort them in alphabetical order.

# Program to input and sort a list of students alphabetically

# Get the number of students from the user


num_students = int(input("Enter the number of students: "))

# Create an empty list to store student names


students = []

# Input the names of the students


for i in range(num_students):
name = input(f"Enter the name of student {i+1}: ")
students.append(name)

# Sort the list alphabetically


students_sorted = sorted(students)

# Print the sorted list of students


print("\n Students sorted alphabetically:")
for student in students_sorted:
print(student)
5. Make a dictionary dataset of all cities in India and store their average temperature
and pollution details.

# Program to store city data with average temperature and pollution details

# Creating a dictionary to store city data


city_data = {
"Delhi": {
"average_temperature": 25.0, # in Celsius
"pollution_level": "High" # Pollution level description
},
"Mumbai": {
"average_temperature": 27.5,
"pollution_level": "Moderate"
},
"Bangalore": {
"average_temperature": 24.0,
"pollution_level": "Low"
},
"Chennai": {
"average_temperature": 29.0,
"pollution_level": "Moderate"
},
"Kolkata": {
"average_temperature": 26.5,
"pollution_level": "High"
},
"Hyderabad": {
"average_temperature": 25.5,
"pollution_level": "Moderate"
},
"Ahmedabad": {
"average_temperature": 28.0,
"pollution_level": "High"
},
"Pune": {
"average_temperature": 23.5,
"pollution_level": "Low"
},
"Jaipur": {
"average_temperature": 26.0,
"pollution_level": "Moderate"
},
"Lucknow": {
"average_temperature": 24.5,
"pollution_level": "High"
}
}
# Printing the city data
for city, details in city_data.items():
print(f"\nCity: {city}")
print(f"Average Temperature: {details['average_temperature']}°C")
print(f"Pollution Level: {details['pollution_level']}")

You might also like