# Printing a Float and String Error

Page 1 of 1

## 1 Replies - 2259 Views - Last Post: 27 September 2011 - 11:30 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=248799&amp;s=34013215b875ab091386e1613c13744b&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Maximous

Reputation: 0
• Posts: 7
• Joined: 26-September 11

# Printing a Float and String Error

Posted 27 September 2011 - 11:24 AM

I am working on a program that lets you first select if you wish to convert from Fahrenheit to Celsius or vice versa. I am just starting out and learning this by myself.

```# Converts Fahrenheit temperatures to Celsius and Celsius to Fahrenheit

print("Conversions")
# Lists choices
print(" 1. Celsius to Fahrenheit")
print(" 2. Fahrenheit to Celsius")
# Asks the NUMBER of the conversion the user would like to do
choice=input("What would you like to convert (number)? ")
# Detects which conversion the user is asking for
if choice == 1:
# Inputs the Celsius Temperature
celsius=float(input("What is the temperatue in Celsius? "))
# Converts to Fahrenheit
f =(celsius * 1.8 + 32.0)
# Display the Fahrenheit
print("The Temperature is "+f + " Fahrenheit")

else:
# Inputs the Fahrenheit Temperature
fahrenheit=float(input("What is the temperature in Fahrenheit? "))
# Converts to Celsius
c =((fahrenheit - 32)* 0.55)
# Display the Celsius
print("The Temperature is "+c+" Celsius")
```

I have two issues
1. When I run the program it will always goto the second conversion even when 1 is chosen
2. When i try to print the temperature conversion and the variable i get the following error
print("The Temperature is "+c+" Celsius")
TypeError: Can't convert 'float' object to str implicitly
If you need to see it run, I attached the file. I would greatly appreciate any help and advice that can be given, Thank You

Is This A Good Question/Topic? 0

## Replies To: Printing a Float and String Error

### #2 Motoma

Reputation: 452
• Posts: 798
• Joined: 08-June 10

## Re: Printing a Float and String Error

Posted 27 September 2011 - 11:30 AM

You're casting input from a string to a float on lines 12 and 20, but on line 8 you'll need to cast to an integer. You need to do this because on line 10 you are checking if it is 1 (the number), not "1" the ASCII string.