Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
559 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 Reply

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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...