This Python program reads two numbers and a character from the user.
If the character is R, it calculates the area of a rectangle.
If the character is T, it calculates the area of a triangle using ½ × base × height.
Otherwise, the area is set to zero.
Then, it reads a base salary and a percentage increase, and calculates the final salary.
def calculate_area(a: float, b: float, shape: str) -> float:
if shape == 'R':
return a * b
elif shape == 'T':
return 0.5 * a * b
else:
return 0.0
def calculate_salary(base: float, percent: float) -> float:
bonus = base * percent
return base + bonus
# Read geometry inputs
a = float(input("Enter first number (length or base): "))
b = float(input("Enter second number (width or height): "))
shape = input("Enter shape character (R for rectangle, T for triangle): ").upper()
area = calculate_area(a, b, shape)
print(f"Calculated area: {area:.2f}")
# Read salary inputs
base_salary = float(input("Enter base salary: "))
percent_increase = float(input("Enter percent increase (e.g., 0.10 for 10%): "))
final_salary = calculate_salary(base_salary, percent_increase)
print(f"Final salary with bonus: {final_salary:.0f} Toman")
Calculated area: 10.00
Final salary with bonus: 1100000 Toman