Jonah.Jackson
Jonah.Jackson

Reputation: 25

why is this print statement giving me an error

all of the print statements in the while loop are giving me errors i have no idea why it looks ok on paper so if you have anything let me know im thinking maybe its a problem with the values and the print statement both in one while loop

w = False
a = False
v = False



if action == "w":
    w = True
if action == "v":
    v = True
if action == "a":
    a = True

while w == True:

    volts = input("Volts: ")
    amperes = input("Amps: ")
    volts = int(volts)
    amperes = int(amperes)
    print("Your Watts Are " + volts * amperes)
    w = False

while v == True:

    watts = input("Watts: ")
    amperes = input("Amps: ")
    watts = int(watts)
    amperes = int(amperes)
    print("Your Volts Are " + watts // amperes)
    v == False

while a == True:

    watts = input("Watts: ")
    volts = input("Volts: ")
    watts = int(watts)
    amperes = int(amperes)
    print("Your Amps Are " + watts // volts)
    a = False





end = input("Press Enter to exit")

Upvotes: 0

Views: 40

Answers (1)

dspencer
dspencer

Reputation: 4461

When trying to concatenate a string with an int or float, python will raise a TypeError. You first need to convert the numeric value to a string, for example:

print("Your Amps Are " + str(watts // volts))

Alternatively, you may use string formatting:

print("Your Amps Are {}".format(watts // volts))

or, in python > 3.6:

print(f"Your Amps Are {watts // volts}")

Upvotes: 3

Related Questions