Fin is a financial analyst who needs to verify if the average of three monthly expenses is less than the two smallest monthly expenses. Write a program to calculate this using the conditional operator. The program should output the average value with two decimal places and the two expenses if the average is less than both, along with a corresponding statement.Input format :The first line of input consists of an integer a, representing the first month's expense.The second line consists of an integer b, representing the second month's expense.The third line consists of an integer c, representing the third month's expense.Output format :The first line of output displays the average value in double with two decimal places.The second line of output displays one of the following:If the average is less than the two smallest monthly expenses, print "Average is less than both X and Y " where X and Y are the two smallest expenses.Otherwise, display "Average is not less than both".
Question
Fin is a financial analyst who needs to verify if the average of three monthly expenses is less than the two smallest monthly expenses. Write a program to calculate this using the conditional operator. The program should output the average value with two decimal places and the two expenses if the average is less than both, along with a corresponding statement.Input format :The first line of input consists of an integer a, representing the first month's expense.The second line consists of an integer b, representing the second month's expense.The third line consists of an integer c, representing the third month's expense.Output format :The first line of output displays the average value in double with two decimal places.The second line of output displays one of the following:If the average is less than the two smallest monthly expenses, print "Average is less than both X and Y " where X and Y are the two smallest expenses.Otherwise, display "Average is not less than both".
Solution
Here is a Python program that accomplishes the task:
# Read the expenses
a = int(input())
b = int(input())
c = int(input())
# Calculate the average
average = round((a + b + c) / 3, 2)
# Find the two smallest expenses
expenses = sorted([a, b, c])
smallest1 = expenses[0]
smallest2 = expenses[1]
# Print the average
print(f"{average:.2f}")
# Check if the average is less than the two smallest expenses
if average < smallest1 and average < smallest2:
print(f"Average is less than both {smallest1} and {smallest2}")
else:
print("Average is not less than both")
This program first reads the expenses from the user, then calculates the average and rounds it to two decimal places. It then sorts the expenses in ascending order and takes the first two as the smallest. It prints the average and then checks if the average is less than both of the smallest expenses. If it is, it prints a message saying so, otherwise it prints a message saying the average is not less than both.
Similar Questions
Alice is managing a budget for her monthly expenses. She receives her salary but also has to pay bills. If her salary is greater than or equal to 2000, she can cover all her bills. If her salary is less than 2000, she needs to borrow money. Additionally, if she borrows money, she needs to pay an interest of 5%.Write a program that takes Alice's salary as input, utilizes logical and ternary operators to determine whether she can cover all her bills, and calculates the total amount she needs to pay if she borrows money.Input format :The first line of input consists of a double value 'S', representing Alice's salary.Output format :The output displays whether Alice can pay or not in the following format:If she can pay then the output displays "Alice can cover all her bills."If she cannot pay the output displays the total amount to pay which has been borrowed including the interest with two decimal places.Refer to the sample output for the formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:100 ≤ S ≤ 5000Sample test cases :Input 1 :1000.50Output 1 :1049.47Input 2 :2000.0Output 2 :Alice can cover all her bills.Input 3 :5000.0Output 3 :Alice can cover all her bills.Input 4 :100.0Output 4 :1995.00
Fin is managing salary taxation and wants a program to determine the net salaries based on the provided salary amount. Determine the net salary: If the salary is less than 50000, print "No Tax." For salaries between 50000 (inclusive) and 100000 (exclusive), apply 10% tax and print the net salary after deduction.For 100000 or more, apply 20% tax and print the net salary after deduction.Implement a program that takes Fin's salary as input (integer) and calculates the net salary after converting it into float.Input format :The input consists of an integer value n, representing Fin's monthly salary.Output format :If no tax is applicable, the output prints "No Tax"If a tax is applicable, the output prints "Salary after X% Tax: Y" where X represents the applicable tax percent value and Y represents the net salary after deduction with two decimal places.Refer to the sample output for the formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:1000 ≤ n ≤ 120000Sample test cases :Input 1 :40000Output 1 :No TaxInput 2 :60000Output 2 :Salary after 10% Tax: 54000.00Input 3 :120000Output 3 :Salary after 20% Tax: 960
A farmer wants to assess the average yields of two different crops from their last two harvests. Design a program that takes the yield (in kilograms) for each crop from the two harvests as input.Calculate the average yield of each crop and also determine print which crop had the highest average yield using the conditional (ternary) operator.Input format :The first line consists of two space-separated double values m1 and n1, representing the yields for Crop 1 (in kilograms) for Harvest 1 and Harvest 2, respectively.The second line consists of two space-separated double values m2 and n2, representing the yields for Crop 2 (in kilograms) for Harvest 1 and Harvest 2, respectively.
Single File Programming QuestionProblem StatementJames is a meticulous traveler who is calculating the total cost of his road trip. James considers factors such as distance traveled, gas consumption, average miles per liter, parking fees, and toll charges. The program takes inputs for miles traveled, gas consumed, average miles per liter, parking fees, and toll charges, and computes the total cost using the formula:The result is then displayed with four two-decimal places. The program utilizes arithmetic operators for the calculations.Input format :The first line consists of the total number of miles traveled per day as an integer.The second line consists of the cost of gas per liter as an integer.The third line consists of the average miles per liter of gas as a positive double-point number.The fourth line consists of the parking cost as an integer.The last line consists of the toll cost as an integer.Output format :The output displays a double value representing the total cost calculated based on the given formula with rounded-off to decimal places.Refer to the sample output for the formatting specifications.Code constraints :In the given scenario, the test cases fall under the following constraints:1 ≤ miles ≤ 10050 ≤ cost of gas ≤ 1505.0 ≤ average_miles ≤ 60.010 ≤ parking charge ≤ 10050 ≤ toll cost ≤ 500Sample test cases :Input 1 :1505.01050Output 1 :70.00Input 2 :587010.54565Output 2 :496.67Input 3 :10015060.0100500Output 3 :850.00Note :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.
A person saves his monthly saving according to the given schema. He saves the same amount of money which is equal to the money saved in the immediate previous two months. Assume, initially, he saved 1000 rupees and in the first month he saved another 1000. Your task is to tell how much he had totally saved at the end of ‘n’ monthsInput format :The input consists of an integer ‘n’->No. of months.Output format :Print the total savings at the end of ‘n’ months.Sample test cases :Input 1 :1Output 1 :2000Input 2 :3Output 2 :7000
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.