Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 338
user2755799 Avatar asked Dec 14 '25 12:12

user2755799


2 Answers

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
like image 52
kindall Avatar answered Dec 18 '25 13:12

kindall


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: "))
like image 31
alecxe Avatar answered Dec 18 '25 12:12

alecxe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!