Reputation: 1
I wanna put the output into one line like:
It is not a prime number.
It's common divisors are: 1,2,7,14.
instead of
It is not a prime number.
It's common divisors are:
1,2,7,14.
I am a beginner of python.
Upvotes: 0
Views: 448
Reputation: 571
Welcome to StackOverflow!
I would say you have two simple options here:
print("test", end = '')
print("Hello ", end = '')
print("world!")
# Output should be: Hello world!
Upvotes: 1
Reputation: 2098
You can actually use the first print
function to print everything as one string instead of using the print
function twice.
For instance, you could do :
divisors = [1, 2, 7, 14]
divisors_as_string = [str(d) for d in divisors]
print(divisors_as_string)
# > ["1", "2", "7", "14"]
# use the join method to join all strings in your divisors_as_string list
# note that they will be separated by ", " as is specified before in the join method
print("It is not a prime number. It's common divisors are:"+", ".join(divisors_as_string)+".")
# > It is not a prime number. It's common divisors are: 1, 2, 7, 14.
Feel free to ask for any further help, and don't forget to mark the question as answered if you solved your problem!
Upvotes: 1