Have the user input three values: Number of large (5lb) bags of candy available
ID: 3789827 • Letter: H
Question
Have the user input three values: Number of large (5lb) bags of candy available Number of small (1lb) bags of candy available Size of the order (number of pounds) Determine if the order can be fulfilled. If it is possible to fill the order, print the number of large bags and small bags required to fill the order. If it is not possible, print a message indicating that the order cannot be fulfilled. 1 large bag, 4 small bags, order size 9lbs can fulfill the order using all of the available bags. 2 large bags, 1 small bag, order size 7lbs cannot fulfill the order 2 large bags, 5 small bags, order size 7lbs-can fulfill the order with 1 large bag and 2 small ones.Explanation / Answer
The following code gives you the required functionality:
# your code goes here
lc = int(input('Enter the number of large bags of candy available: '))
sc = int(input('Enter the number of small bags of candy available: '))
n = int(input('Enter the size of input(in pounds)'))
if(n>5):
d = n//5
if(lc >= d):
n = n -(d*5)
num_lb = d
else:
n = n -(lc*5)
num_lb = lc
if(sc >= n):
if(num_lb == lc and n == sc):
print('Can fulfill the order with all bags available')
else:
print('Can fulfill the order with ' + str(num_lb) + ' large bag and ' + str(n) +' small ones')
else:
print('Cannot fulfill the order')
Input 1:
1
4
9
Output:
Input 2:
2
1
9
Output:
Input 3:
2
5
7
Output:
Link of code:
http://ideone.com/2U4Sda
Hope it helps, do give your response.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.