Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Pouring 8 litres into 2 empty container of size 3 and 5 to get 4 litre in any container

# Python Code
import time
print("This a liquid pouring challenge")
print("
You are required to get 4 litres")
print("in any container by emptying and/or leaving in other container")
# C Represents Container
F = 1
while F == 1:
    C1 = 8
    print("
Container 1 which comes fill with 8 litres")
    C2 = 0
    print("Container 2 which comes empty with a MAX of five litres")
    C3 = 0
    print("Container 3 which comes empty with a MAX of 3 litres")

    print("Container 1=", C1, "       Container 2=", C2, "       Container 3=", C3)
    IA1 = int(input("Enter the Amount you wish to pour from Container 1 to Container 2: "))
    C1 -= IA1
    C2 = IA1
    IA2 = int(input("Enter the Amount you wish to pour from Container 2 to Container 3: "))
    C2 -= IA2
    C3 = IA2
    IA3 = int(input("Enter the Amount you wish to pour from Container 3 To Container 1: "))
    C3 -= IA3
    C1 += IA3
    IA4 = int(input("Enter the Amount you wish to pour from Container 2 to Container 3: "))
    C2 -= IA4
    C3 = IA4
    IA5 = int(input("Enter the Amount you wish to pour from Container 1 to Container 2: "))
    C1 -= IA5
    C2 += IA5
    IA6 = int(input("Enter the Amount you wish to pour from Container 2 to Container 3: "))
    C2 -= IA6
    C3 += IA6
    IA7 = int(input("Enter the Amount you wish to pour from Container 3 to Container 1: "))
    C1 += IA7

    if C2 > 5:
        print("
Container 2 is running over")
    if C3 > 3:
        print("
Container 3 is running over")
    if C1 == 4 or C2 == 4:
        print("
Goal has been achieved, you have successfully put 4 litre in a container")
        print("Congratulation!!!!!")
        F = 0
    else:
        print("
Your have failed!!!!")
        F = 1

    print("
Container 1 now has ", C1, " litres")
    print("Container 2 now has ", C2, " litres")

time.sleep(5.5)
Source by www.codegrepper.com #
 
PREVIOUS NEXT
Tagged: #Pouring #litres #empty #container #size #litre #container
ADD COMMENT
Topic
Name
4+8 =