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.
Question
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.
Solution
Here is a Python program that accomplishes the task:
# Get the input for Crop 1
m1, n1 = map(float, input().split())
# Get the input for Crop 2
m2, n2 = map(float, input().split())
# Calculate the average yield for each crop
avg_yield_crop1 = (m1 + n1) / 2
avg_yield_crop2 = (m2 + n2) / 2
# Print the average yield for each crop
print("Average yield for Crop 1: ", avg_yield_crop1)
print("Average yield for Crop 2: ", avg_yield_crop2)
# Determine and print which crop had the highest average yield
print("Crop 1 had the highest average yield" if avg_yield_crop1 > avg_yield_crop2 else "Crop 2 had the highest average yield")
This program first takes the yield for each crop from the two harvests as input. It then calculates the average yield for each crop by adding the yields from the two harvests and dividing by 2. It prints the average yield for each crop. Finally, it uses the conditional (ternary) operator to determine which crop had the highest average yield and prints this information.
Similar Questions
Single File Programming QuestionProblem StatementA 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.Output format :The first line prints "Crop 1: X kg" where X is a double value representing the average yield of Crop 1 in both harvests rounded to two decimal places.The second line prints "Crop 2: Y kg" where X is a double value representing the average yield of Crop 2 in both harvests rounded to two decimal places.The third line prints "Crop Z had the highest average yield" where Z is the crop number that had the highest yield.Refer to the sample output for the formatting specifications.Code constraints :In the given scenario, test cases fall under the following constraints:100.0 ≤ m1, n1, m2, n2 ≤ 1000.0Sample test cases :Input 1 :152.2 125.1100.0 123.0Output 1 :Crop 1: 138.65 kgCrop 2: 111.50 kgCrop 1 had the highest average yieldInput 2 :456.2 567.4965.0 1000.0Output 2 :Crop 1: 511.80 kgCrop 2: 982.50 kgCrop 2 had the highest average yieldNote :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.
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.Output format :The first line prints "Crop 1: X kg" where X is a double value representing the average yield of Crop 1 in both harvests rounded to two decimal places.The second line prints "Crop 2: Y kg" where X is a double value representing the average yield of Crop 2 in both harvests rounded to two decimal places.The third line prints "Crop Z had the highest average yield" where Z is the crop number that had the highest yield.Refer to the sample output for the formatting specifications.
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 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".
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.