A farmer sells tomatoes. For some reason, the farm obeys mechanical laws of fate.
If he sells at least a dozen tomatoes, he receives two watermelons.
If he sells exactly two dozen tomatoes, he receives four more watermleons.
On the days that he sells less than a dozen tomatoes, the farmer will get a single apple.
Write a Python Code that uses if/else statements that accounts for all of these possible scenarios.
Use the variables tomatoes, watermelons, and apples in each statement, but be careful not to re-define them (that is, they are provided to you already).

Respuesta :

Answer:

Here are the if/elif statements:

if tomatoes == 24:  #if farmer sells exactly two dozen tomatoes

   watermelons +=4  #farmer receives 4 watermelons

elif tomatoes >= 12:  #else farmer sells at least a dozen tomatoes

   watermelons +=2  #farmer receives 2 watermelons

else:

   tomatoes<12   #On the days that farmer sells less than a dozen tomatoes

   apples +=1  #farmer will get a single apple

Explanation:

You can test the working of these if elif statements by this program:

tomatoes = int(input("Enter the amount of tomatoes sold: "))  #prompts user to enter number of tomatoes

watermelons = 0  #initialize watermelons value to 1

apples = 0  #initialize apples value to 1

if tomatoes == 24:

   watermelons +=4

elif tomatoes >= 12:

   watermelons +=2

else:  

   tomatoes<12

   apples +=1

   

print("Number of watermelons recieved: ",watermelons)  #displays the received number of watermelons

print("Number of apples recieved: ",apples )  #displays the received number of apples

Ver imagen mahamnasir