Why this conversion program does not work?

63 Views Asked by At

I am trying to figure out what is wrong in here. Any help is very appreciated. I think one of the problem is the declaration of the variable that is inside the method. Can I make a global variable from the method?

    def cycle():
    choice = None
    while not choice:
        newcalc = input('Do you want to make a new calculation? \n \t (Y/N)')
        if newcalc.lower() in ["no", "n"]:
            choice = "no"

        if newcalc.lower() in ["yes", "y"]:
            choice = "yes"
        else:
            print('This is not the right answer')
            continue
    return choice
def counting_M(data):
    while True:
        concersion_1 = input('Do you want to convert from M to uM? (Y/N)')
        if concersion_1.lower() in ["y", "yes"]:
            print('This is the result of the conversion {} uM'.format(str(data/1000)))
        else:
            print('Not converting')
        while True:
            mw = input('What is the Molecular Weight of your compound, please in g/M?')
            try:
                mw = float(mw)
                break
            except ValueError:
                print("Not a valid float!")

        print('Your coumpound weights ug/ml', str((data/1000) / (mw / 1000)))
def measure():
    while True :
        data = input('Please, provide the absolute amount of compound you have, without units \n \t')
        try:
            data = float(data)
            break
        except ValueError:
            print("Not a valid float value!")
        units = input('Please, indicate the measure unit you have \n  A)M, B)mM, C)uM '
                      '\n 1A)g/liter, 2A)mg/ml, 3A)ug/ml \n \t')
        if units.lower() == "a":
            print('Ok so you have M')
            counting_M(data)
            choice = cycle()
            print(choice)
        elif units.lower() == "b":
            print('Ok so you have mM')
            counting_M(data)
            choice = cycle()
            print(choice)
        elif units.lower() == "c":
            print('Ok so you have uM which it the right concentration')
            cycle()
        elif units.lower() == "1a":
            print('Ok so you have g/liter you have now mg/ml')
            counting_M(data)
            choice = cycle()
            print(choice)
        elif units.lower() == "2a":
            print('Ok so you have mg/ml')
            counting_M(data)
            choice = cycle()
            print(choice)
        elif units.lower() == "3a":
            print('Ok so you have ug/ml, hence nothing to do')
            cycle()
        else:
            print('You have to select one of the options above')


counting_M(data)
choice = cycle()
print(choice)

Thank you for your help

0

There are 0 best solutions below