Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

ASSIGMENT-2

Name-Saransh Kanwadia
Class-XI-G

Question-1

def check_even_or_odd(number):
if number % 2 == 0:
return "Even"
else:
return "Odd"

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


result = check_even_or_odd(number)
print(f"The number {number} is {result}.")

OUTPUT

Enter a number: 34
The number 34 is Even.

Question-2

def find_absolute_value(number):
if number < 0:
return -number
elif number > 0:
return number
else:
return 0

number = float(input("Enter a number: "))


absolute_value = find_absolute_value(number)
print(f"The absolute value of {number} is {absolute_value}.")

OUTPUT
Enter a number: 46
The absolute value of 46.0 is 46.0.

QUESTION-3

def determine_number_type(number):
if number > 0:
return "Positive"
elif number < 0:
return "Negative"
else:
return "Zero"

number = int(input("Enter an integer: "))


result = determine_number_type(number)
print(f"The number {number} is {result}.")

OUTPUT

Enter an integer: 465


The number 465 is Positive.

QUESTION-4
def is_leap_year(year):
if year % 400 == 0:
return True
elif year % 4 == 0 and year % 100 != 0:
return True
else:
return False

year = int(input("Enter a year (YYYY): "))


if is_leap_year(year):
print(f"{year} is a leap year.")
else:
print(f"{year} is not a leap year.")
OUTPUT
Enter a year (YYYY): 2086
2086 is not a leap year.

QUESTION-5

def find_largest_of_three(num1, num2, num3):


if num1 >= num2 and num1 >= num3:
return num1
elif num2 >= num1 and num2 >= num3:
return num2
else:
return num3

num1 = float(input("Enter the first number: "))


num2 = float(input("Enter the second number: "))
num3 = float(input("Enter the third number: "))

largest = find_largest_of_three(num1, num2, num3)


print(f"The largest of the three numbers is: {largest}")

OUTPUT
Enter the first number: 34
Enter the second number: 57
Enter the third number: 86
The largest of the three numbers is: 86.0

QUESTION-6

def calculate_profit_or_loss(cp, sp):


if sp == cp:
return "No profit, No loss"
elif sp > cp:
return f"Profit of {sp - cp}"
else:
return f"Loss of {cp - sp}"

description = input("Enter the description of the item: ")


cp = float(input("Enter the cost price (CP) of the item: "))
sp = float(input("Enter the selling price (SP) of the item: "))
result = calculate_profit_or_loss(cp, sp)
print(f"Item Description: {description}")
print(f"Result: {result}")

OUTPUT

Enter the description of the item: parker pen


Enter the cost price (CP) of the item: 140
Enter the selling price (SP) of the item: 180
Item Description: parker pen
Result: Profit of 40.0

QUESTION-7

def calculate_grade(total_marks):
percentage = (total_marks / 500) * 100
if percentage >= 90:
return "A"
elif percentage >= 80:
return "B"
elif percentage >= 70:
return "C"
elif percentage >= 60:
return "D"
else:
return "E"
total_marks = float(input("Enter total marks (out of 500): "))
print(calculate_grade(total_marks))

OUTPUT

Enter total marks (out of 500): 450


A

QUESTION-8

def calculate_income_tax(income):
if income <= 300000:
tax = 0
elif income <= 500000:
tax = (income - 300000) * 0.05
elif income <= 1000000:
tax = 200000 * 0.05 + (income - 500000) * 0.20
else:
tax = 200000 * 0.05 + 500000 * 0.20 + (income - 1000000) * 0.30

educational_cess = tax * 0.03


total_tax = tax + educational_cess
return total_tax

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


print("Total tax to be paid is:", calculate_income_tax(income))

OUTPUT
Enter your income: 5500000
Total tax to be paid is: 1503800.0

You might also like