2 Replies - 206 Views - Last Post: 04 February 2014 - 06:09 AM Rate Topic: -----

#1 bigbeezy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 06-January 13

Why is the last line showing the all the ' when I run it?

Posted 03 February 2014 - 09:19 PM

celsius = float(input('Enter a temperature: ' ))
fahrenheit = 9.0 / 5.0 * celsius + 32
print("The temperature is", fahrenheit, " degrees Fahrenheit.")
Is This A Good Question/Topic? 0
  • +

Replies To: Why is the last line showing the all the ' when I run it?

#2 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3524
  • View blog
  • Posts: 12,031
  • Joined: 12-December 12

Re: Why is the last line showing the all the ' when I run it?

Posted 03 February 2014 - 09:54 PM

The code works for me:

Enter a temperature: 22
The temperature is 71.6  degrees Fahrenheit.

Was This Post Helpful? 0
  • +
  • -

#3 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2118
  • View blog
  • Posts: 3,244
  • Joined: 21-June 11

Re: Why is the last line showing the all the ' when I run it?

Posted 04 February 2014 - 06:09 AM

When you say "showing all the '", do you mean that the output is literally as follows?

Quote

("The temperature is", fahrenheit, " degrees Fahrenheit.")


If so, you're using Python 2. In python 2 the syntax for print is print expressions where expressions is a list of expressions either separated by commas or semicolons. Notably there are no parentheses around that list. So when Python sees print(bla,bla), it treats that as print being used on a single value and that value being the tuple (bla, bla). So it prints it as a tuple.

So when trying to print multiple values using Python 2, don't use parentheses.
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1