Home > other >  TypeError: float() argument must be a string or a real number, not 'dict'
TypeError: float() argument must be a string or a real number, not 'dict'

Time:02-20

default_value=input("Please enter the trignometric operation u would like to perform : ")

import math



trignometry_tables={

    "sin 0"      : 0,
    "sin 30"     : 1/2,
    "sin 45"     : 1/math.sqrt(2),
    "sin 60"     : math.sqrt(3)/2,
    "sin 90"     : 1,
    "cos 0"      : 1,
    "cos 30"     : math.sqrt(3)/2,
    "cos 45"     : 1/math.sqrt(2),
    "cos 60"     : 1/2,
    "cos 90"     : 0,
    "tan 0"      : 0,
    "tan 30"     : 1/math.sqrt(3),
    "tan 45"     : 1,
    "tan 60"     : math.sqrt(3),
    "tan 90"     : "not defined",
    "cosec 0"    : "not defined",
    "cosec 30"   : 2,
    "cosec 45"   : math.sqrt(2),
    "cosec 60"   : 2/math.sqrt(3),
    "cosec 90"   : 1,
    "sec 0"      : 1,
    "sec 30"     : 2/math.sqrt(3),
    "sec 45"     : math.sqrt(2),
    "sec 60"     : 2 ,
    "sec 90"     : "not defined",
    "cotan 0"    : "not defined",
    "cotan 30"   : math.sqrt(3),
    "cotan 45"   : 1,
    "cotan 60"   : 1/math.sqrt(3),
    "cotan 90"   : 0

}





if default_value=="sin" :


    opposite=input("Please enter the opposite value :")

    for values in trignometry_tables:
        opposite=trignometry_tables
            
    

    hypotnuse=input("Please enter the hypotnuse value :")
    cal=float(opposite)/float(hypotnuse)

    print(cal)

Now the let me explain what I want :

Now when I type for example "sin 0" in the opposite I would like the program to go back to the dictionary(for here it is that trignometry_table) and find the value which I have assigned it to. And simply just substitute that value for example instead of that sin 0 I would like to get that assigned value 0 and calculate it

CodePudding user response:

if default_value=="sin" :


    opposite=input("Please enter the opposite value :")

    opposite=trignometry_tables.get(opposite) 
            
    

    hypotnuse=input("Please enter the hypotnuse value :")
    hypotnuse=trignometry_tables.get(hypotnuse)
    cal=float(opposite)/float(hypotnuse)

    print(cal)

Does it help?

Note: You also need to look for Division by Zero and how to handle "not defined" values.

  • Related