Search
 
SCRIPT & CODE EXAMPLE
 

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)
Comment

PREVIOUS NEXT
Code Example
Python :: django.db.utils.IntegrityError: column contains null values 
Python :: python geet second item in generator 
Python :: keep only min entries in dataframe grouped by one column 
Python :: python pipe select where dedup 
Python :: hexing floats 
Python :: Slice Age in Python 
Python :: write a python program which accepts the user 
Python :: check if a string is a palindrome python 
Python :: Freqtrade - sell after x candels 
Python :: COLLECTING 
Python :: how to add to an index in a list in python 
Python :: qaction disacble python 
Python :: tanimoto coefficient rdkit 
Python :: os.startfile on raspberry 
Python :: range coding 
Python :: pandas sample frac 
Python :: python range for loop 
Python :: how to do square roots in python 
Python :: odd and even python 
Python :: pygame get rect 
Python :: get member by id discord py 
Python :: python parse xml string 
Python :: how to plot using matplotlib 
Python :: select python interpreter vscode 
Python :: python official documentation 
Python :: pd.explode 
Python :: how to find the average in python 
Python :: import libraries to Jupyter notebook 
Python :: creating an object in python 
Python :: precedence in python 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =