user2755799
user2755799

Reputation: 41

TypeError: can't multiply sequence by non-int of type 'float' 3.3

Ok I have edited the code to where it would hopefully work but I get the TypeError: can't multiply sequence by non-int of type 'float'.

Heres the code that I have:

uTemp = input("Enter Temperature Variable: ")

cOrF = input("Do you want C for celcius, or F for Farehnheit?: ")

if cOrF:
    F = 1.8 * uTemp + 32

Upvotes: 3

Views: 18621

Answers (2)

kindall
kindall

Reputation: 184415

The error is telling you that you can't multiply uTemp, a string, by a floating-point number (1.8). Which makes perfect sense, right? What is eight tenths of a string? Convert uTemp to a float:

uTemp = float(input("Enter Temperature Variable: "))

Your next problem is that cOrF is treated as a Boolean (true/false) value, which means F will be calculated if the user enters anything at that prompt since all non-empty strings are truthy in Python. So instead you would write:

if cOrF == "F":
    F = 1.8 * uTemp + 32

Upvotes: 7

alecxe
alecxe

Reputation: 474211

input() returns a string in python 3.x.

Convert it to float (or to int - depends on your needs):

uTemp = float(input("Enter Temperature Variable: "))

Upvotes: 6

Related Questions