Example #1
0
def func_eleven(calc_cleaned, molar_mass):
    calc = analyze_what_calc(calc_cleaned)
    if calc == 'g':
        moles = how_many_moles()
        formatted_moles = format_moles(moles)
        float_bool_value = confirm_float_moles(formatted_moles)
        while float_bool_value == False:
            bool_not_float = handle_not_float(formatted_moles)
            if bool_not_float == True:
                sys.exit()

            else:
                print("I'm sorry, but you did not enter a floating-point \
value. Please try again." + '\n')
                moles = how_many_moles()
                formatted_moles = format_moles(moles)
                float_bool_value = confirm_float_moles(formatted_moles)
                continue
        moles = make_moles_float(moles)
        grams = moles_to_grams(moles, molar_mass)
        answer = str(grams) + ' ' + 'g'
        print('\n')
        print("You have " + answer + '\n')

    elif calc == 'm':
        grams = how_many_grams()
        formatted_grams = format_grams(grams)
        float_bool_value = confirm_float_grams(formatted_grams)
        while float_bool_value == False:
            bool_not_float = handle_not_float(formatted_grams)
            if bool_not_float == True:
                sys.exit()

            else:
                print("I'm sorry, but you did not enter a floating-point \
value. Please try again." + '\n')
                grams = how_many_grams()
                formatted_grams = format_grams(grams)
                float_bool_value = confirm_float_grams(formatted_grams)
                continue
        grams = make_grams_float(grams)
        moles = grams_to_moles(grams, molar_mass)
        answer = str(moles) + ' ' + 'mol'
        print('\n')
        print("You have " + answer + '\n')
Example #2
0
def func_eleven(calc_cleaned, molar_mass):
    calc = analyze_what_calc(calc_cleaned)
    if calc == 'g':
        moles = how_many_moles()
        formatted_moles = format_moles(moles)
        float_bool_value = confirm_float_moles(formatted_moles)
        while float_bool_value == False:
            bool_not_float = handle_not_float(formatted_moles)
            if bool_not_float == True:
                sys.exit()

            else:
                print("I'm sorry, but you did not enter a floating-point \
value. Please try again." + '\n')
                moles = how_many_moles()
                formatted_moles = format_moles(moles)
                float_bool_value = confirm_float_moles(formatted_moles)
                continue
        moles = make_moles_float(moles)
        grams = moles_to_grams(moles,molar_mass)
        answer = str(grams) + ' ' + 'g'
        print('\n')
        print("You have " + answer + '\n')

    elif calc == 'm':
        grams = how_many_grams()
        formatted_grams = format_grams(grams)
        float_bool_value = confirm_float_grams(formatted_grams)
        while float_bool_value == False:
            bool_not_float = handle_not_float(formatted_grams)
            if bool_not_float == True:
                sys.exit()

            else:
                print("I'm sorry, but you did not enter a floating-point \
value. Please try again." + '\n')
                grams = how_many_grams()
                formatted_grams= format_grams(grams)
                float_bool_value = confirm_float_grams(formatted_grams)
                continue
        grams = make_grams_float(grams)
        moles = grams_to_moles(grams,molar_mass)
        answer = str(moles) + ' ' + 'mol'
        print('\n') 
        print("You have " + answer + '\n')
Example #3
0
 def test_one(self):
     grams = 5.321
     molar_mass = 89.123
     self.assertAlmostEqual(grams_to_moles(grams, molar_mass), 0.059704005)
 def test_one(self):
     grams = 5.321
     molar_mass = 89.123
     self.assertAlmostEqual(grams_to_moles(grams, molar_mass), 0.059704005)