In: Computer Science
You can assume that the bottles in a single order are all of the same size.
Given an order, the problem is to calculate the number of litres of lemonade required to fill all the bottles for that order.
The number of litres required for a single bottle is calculated as follows: Multiply 0.9560 with 1, 2 or 3 depending on whether the bottle size is ‘small’, ‘medium’ and ‘large’, respectively.
Part iii of this question involves writing one Python function definition.
iii.Provide a single Python function that implements the algorithm. Follow the instructions above for submitting code.
Your answer must be a translation of your algorithm from part c (ii), otherwise no marks will be awarded.
Solution:
C(i)
Take the total number of bottles required for the user
Take the size of the bottle required i.e small,medium,large
calculate the number of litres for each size
if size is "small" then
>> output =number of bottles required *0.9560*1
if size is "medium" then
>> output =number of bottles required *0.9560*2
if size is "large" then
>> output =number of bottles required *0.9560*3
C(ii)
Step1:
Take the total number of bottles required for the user
Step2:
Take the size of the bottle required i.e small,medium,large
Step3:
if size is "small" then
output =number of bottles required *0.9560*1
Step4:
if size is "medium" then
output =number of bottles required *0.9560*2
Step5:
if size is "large" then
output =number of bottles required *0.9560*3
C(iii)
def solution(cou,sie):
value=0.9560
result=cou*sie*value
return result
B_count=float(input("enter the number of required bottles:"))
size_string=input("enter the size small,medium or large:")
if(size_string=="small"):
size=1.0
elif(size_string=="medium"):
size=2.0
elif(size_string=="large"):
size=3.0
print(size)
res=solution(B_count,size)
print(res)