Ryan Joachim
Ryan Joachim

Reputation: 81

print() is showing quotation marks in results

When the below portion of the script is activated, it shows all the commas and single quotes (and parentheses) in the results.

print(name, 'has been alive for', days, 'days', minutes, 'minutes and', seconds, 'seconds!')

So, for instance:

('Ryan', 'has been alive for', 10220, 'days', 14726544, 'minutes and', 883593928, seconds!')

I want to clean it up, so it looks good. Is that possible?

By "good", I mean something like this:

Ryan has been alive for 10220 days, 14726544 minutes, and 883593928 seconds!

Here is the full script:

print("Let's see how long you have lived in days, minutes, and seconds!")
name = raw_input("name: ")

print("now enter your age")
age = int(input("age: "))

days = age * 365
minutes = age * 525948
seconds = age * 31556926

print(name, 'has been alive for', days, 'days', minutes, 'minutes and', seconds, 'seconds!')

raw_input("Hit 'Enter' to exit!: ")

Upvotes: 3

Views: 7598

Answers (1)

Two-Bit Alchemist
Two-Bit Alchemist

Reputation: 18457

You need from __future__ import print_function.

In Python 2.x what you are doing is interpreted as printing a tuple, while you are using the 3.x syntax.

Example:

>>> name = 'Ryan'
>>> days = 3
>>> print(name, 'has been alive for', days, 'days.')
('Ryan', 'has been alive for', 3, 'days.')
>>> from __future__ import print_function
>>> print(name, 'has been alive for', days, 'days.', sep=', ')
Ryan, has been alive for, 3, days.

Upvotes: 7

Related Questions