Why am I getting a " Traceback (most recent call last):" error?

python

Solution

At the beginning of your file you set `raw_input` to 0. Do not do this, at it modifies the built-in `raw_input()` function. Therefore, whenever you call `raw_input()`, it is essentially calling `0()`, which raises the error. To remove the error, remove the first line of your code:

M = 1.6
# Miles to Kilometers 
# Celsius Celsius = (var1 - 32) * 5/9
# Gallons to liters Gallons = 3.6
# Pounds to kilograms Pounds = 0.45
# Inches to centimete Inches = 2.54


def intro():
    print("Welcome! This program will convert measures for you.")
    main()

def main():
    print("Select operation.")
    print("1.Miles to Kilometers")
    print("2.Fahrenheit to Celsius")
    print("3.Gallons to liters")
    print("4.Pounds to kilograms")
    print("5.Inches to centimeters")

    choice = input("Enter your choice by number: ")

    if choice == '1':
        convertMK()

    elif choice == '2':
        converCF()

    elif choice == '3':
        convertGL()

    elif choice == '4':
        convertPK()

    elif choice == '5':
        convertPK()

    else:
        print("Error")


def convertMK():
    input_M = float(raw_input(("Miles: ")))
    M_conv = (M) * input_M
    print("Kilometers: %f\n" % M_conv)
    restart = str(input("Do you wish to make another conversion? [y]Yes or [n]no: "))
    if restart == 'y':
        main()
    elif restart == 'n':
        end()
    else:
        print("I didn't quite understand that answer. Terminating.")
        main()

def converCF():
    input_F = float(raw_input(("Fahrenheit: ")))
    F_conv = (input_F - 32) * 5/9
    print("Celcius: %f\n") % F_conv
    restart = str(input("Do you wish to make another conversion? [y]Yes or [n]no: "))
    if restart == 'y':
        main()
    elif restart == 'n':
        end()
    else:
        print("I didn't quite understand that answer. Terminating.")
        main()

def convertGL():
    input_G = float(raw_input(("Gallons: ")))
    G_conv = input_G * 3.6
    print("Centimeters: %f\n" % G_conv)
    restart = str(input("Do you wish to make another conversion? [y]Yes or [n]no: "))
    if restart == 'y':
        main()
    elif restart == 'n':
        end()
    else:
        print ("I didn't quite understand that answer. Terminating.")
        main()

def convertPK():
    input_P = float(raw_input(("Pounds: ")))
    P_conv = input_P * 0.45
    print("Centimeters: %f\n" % P_conv)
    restart = str(input("Do you wish to make another conversion? [y]Yes or [n]no: "))
    if restart == 'y':
        main()
    elif restart == 'n':
        end()
    else:
        print ("I didn't quite understand that answer. Terminating.")
        main()

def convertIC():
    input_cm = float(raw_input(("Inches: ")))
    inches_conv = input_cm * 2.54
    print("Centimeters: %f\n" % inches_conv)
    restart = str(input("Do you wish to make another conversion? [y]Yes or [n]no: "))
    if restart == 'y':
        main()
    elif restart == 'n':
        end()
    else:
        print ("I didn't quite understand that answer. Terminating.")
        main()

def end():
    print("This program will close.")
    exit()

intro()

Problem

I'm sorry for asking, but I can't find why I'm getting this errors, especially after the program is running. The erros to be exact are: ``` >>> Welcome! This program will convert measures for you. Select operation. 1.Miles to Kilometers 2.Fahrenheit to Celsius 3.Gallons to liters 4.Pounds to kilograms 5.Inches to centimeters Enter your choice by number: 1 Traceback (most recent call last): File "C:\Users\Levhitor\Downloads\Mario_Gomez_Lab2.py", line 112, in <module> intro() File "C:\Users\Levhitor\Downloads\Mario_Gomez_Lab2.py", line 12, in intro main() File "C:\Users\Levhitor\Downloads\Mario_Gomez_Lab2.py", line 25, in main convertMK() File "C:\Users\Levhitor\Downloads\Mario_Gomez_Lab2.py", line 44, in convertMK input_M = float(raw_input(("Miles: "))) TypeError: 'int' object is not callable ``` I don't understand what's happening here. Can anyone help me? ``` raw_input = 0 M = 1.6 # Miles to Kilometers # Celsius Celsius = (var1 - 32) * 5/9 # Gallons to liters Gallons = 3.6 # Pounds to kilograms Pounds = 0.45 # Inches to centimete Inches = 2.54 def intro(): print("Welcome! This program will convert measures for you.") main() def main(): print("Select operation.") print("1.Miles to Kilometers") print("2.Fahrenheit to Celsius") print("3.Gallons to liters") print("4.Pounds to kilograms") print("5.Inches to centimeters") choice = input("Enter your choice by number: ") if choice == '1': convertMK() elif choice == '2': converCF() elif choice == '3': convertGL() elif choice == '4': convertPK() elif choice == '5': convertPK() else: print("Error") def convertMK(): input_M = float(raw_input(("Miles: "))) M_conv = (M) * input_M print("Kilometers: %f\n" % M_conv) restart = str(input("Do you wish to make another conversion? [y]Yes or [n]no: ")) if restart == 'y': main() elif restart == 'n': end() else: print("I didn't quite understand that answer. Terminating.") main() def converCF(): input_F = float(raw_input(("Fahrenheit: "))) F_conv = (input_F - 32) * 5/9 print("Celcius: %f\n") % F_conv restart = str(input("Do you wish to make another conversion? [y]Yes or [n]no: ")) if restart == 'y': main() elif restart == 'n': end() else: print("I didn't quite understand that answer. Terminating.") main() def convertGL(): input_G = float(raw_input(("Gallons: "))) G_conv = input_G * 3.6 print("Centimeters: %f\n" % G_conv) restart = str(input("Do you wish to make another conversion? [y]Yes or [n]no: ")) if restart == 'y': main() elif restart == 'n': end() else: print ("I didn't quite understand that answer. Terminating.") main() def convertPK(): input_P = float(raw_input(("Pounds: "))) P_conv = input_P * 0.45 print("Centimeters: %f\n" % P_conv) restart = str(input("Do you wish to make another conversion? [y]Yes or [n]no: ")) if restart == 'y': main() elif restart == 'n': end() else: print ("I didn't quite understand that answer. Terminating.") main() def convertIC(): input_cm = float(raw_input(("Inches: "))) inches_conv = input_cm * 2.54 print("Centimeters: %f\n" % inches_conv) restart = str(input("Do you wish to make another conversion? [y]Yes or [n]no: ")) if restart == 'y': main() elif restart == 'n': end() else: print ("I didn't quite understand that answer. Terminating.") main() def end(): print("This program will close.") exit() intro() ``` I do not know what is wrong... can anyone help me? Thanks you!

Original source

Related problems