I am very new to Python but very interested in learning. For a uni Python course I am to create a program that converts a temp to Celsius or Fahrenheit, and displays the conversion to the first decimal place. My issue lies in my print lines.
As you can see in my code I have attempted to use the round() function while concatenating. Although I have attempted to convert the would be float to a str(), when I run my program, i am given the following error.
TypeError: type str doesn't define round method
for the following line
print (round(str(temp), 1)+ " degrees celsius = " + str(degF) + " degrees Fahrenheit. ")
and similarly for the print line in my elif bloc. Any help understanding and solving the issue would be greatly appreciated.
temp=float(input("Enter a temperature value to convert: "))
unit=str(input("Convert to Fahrenheit or Celsius? Enter f or c: "))
if unit=="c" or unit == "C":
degC=(temp)
temp=(1.8*temp)+32
print (round(str(temp), 1) + " degrees fahrenheit = " + str(degC) + " degrees Celsius. ")
elif unit=="f" or unit == "F":
degF=(temp)
temp=(temp-32)/1.8
print (round(str(temp), 1)+ " degrees celsius = " + str(degF) + " degrees Fahrenheit. ")
else:
print("you did not enter an f or c. Goodbye ")
My outputs should be rounded to the first decimal place.