Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
552 views
in Technique[技术] by (71.8m points)

python - 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!: ")
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...