0% found this document useful (0 votes)
4 views3 pages

Optimal Crop Yield Calculation in Python

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Optimal Crop Yield Calculation in Python

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

ASSIGNMENT-4

Student Name: Suraj Singh UID:22BCS15705


Branch: CSE Section/Group: 720-A
Semester: 4th Date of Performance: 18/04/24
Subject Name: Python Programming Subject Code: 22CSH-259

1. Aim:

You are a farmer planning to grow two types of crops, Crop A and Crop B, on
your farmland. Each type of crop requires a certain amount of water and
fertilizer to grow, and you have a limited amount of both resources available.
The objective is to maximize the total yield of crops while respecting the
resource constraints. Maximize the total yield of crops.
Crop details:

Crop A: Requires 5 gallons of water and 2 bags of fertilizer per acre.


Crop B: Requires 3 gallons of water and 4 bags of fertilizer per acre.

Constraints:
Limited availability of water: You have 50 gallons of water available.
Limited availability of fertilizer: You have 40 bags of fertilizer available.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

2. Source Code:
crop_requirements = {
'Crop A': {'Water': 5, 'Fertilizer': 2},
'Crop B': {'Water': 3, 'Fertilizer': 4}
}

available_resources = {
'Water': 50,
'Fertilizer': 40
}

max_yield = 0
max_distribution = {}

for num_crop_A in range(available_resources['Water'] // crop_requirements['Crop


A']['Water'] + 1):
for num_crop_B in range(available_resources['Water'] //
crop_requirements['Crop B']['Water'] + 1):
water_used = num_crop_A * crop_requirements['Crop A']['Water'] +
num_crop_B * crop_requirements['Crop B']['Water']
if water_used <= available_resources['Water']:
for num_fertilizer_A in range(available_resources['Fertilizer'] //
crop_requirements['Crop A']['Fertilizer'] + 1):
for num_fertilizer_B in range(available_resources['Fertilizer'] //
crop_requirements['Crop B']['Fertilizer'] + 1):
fertilizer_used = num_fertilizer_A * crop_requirements['Crop
A']['Fertilizer'] + num_fertilizer_B * crop_requirements['Crop B']['Fertilizer']
if fertilizer_used <= available_resources['Fertilizer']:
total_yield = num_crop_A + num_crop_B
if total_yield > max_yield:
max_yield = total_yield
max_distribution = {'Crop A': num_crop_A, 'Crop B':
num_crop_B}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

print("Optimal crop planning:")


for crop, acres in max_distribution.items():
print(f"{crop}: {acres} acres")
print("Total yield:", max_yield)

3. Screenshot of Outputs:

You might also like