为什么这个转换程序不起作用?

时间:2016-12-24 12:49:39

标签: python python-3.x loops global-variables python-3.6

我想弄清楚这里有什么问题。非常感谢任何帮助。我认为其中一个问题是方法内部变量的声明。我可以从方法中创建一个全局变量吗?

    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)

感谢您的帮助

0 个答案:

没有答案