How to join lines? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to join lines?

Hello, making a game to help kids learn English. How do I get lines to join? For example, right now (if you run this code) you'll see that "named" and "input" and "Who lived" are on three separate lines? How do I get them to all output on one line? Thanks. UNI = input("Welcome ") print(UNI) print("Dragon or Unicorn?") Drag_or_Uni = input("\nSo you chose ") print(Drag_or_Uni) print("Once upon a time there was a young unicorn named ") print(UNI) print("Who lived in a magical forest. This world is yours to explore and themore answers you get correct the more powers you will have. Let's begin.....")

21st Apr 2019, 10:44 PM
tristach605
tristach605 - avatar
5 Answers
+ 5
Various methods to get output on the same line: name = 'tristach605' print('Your name is', name) print('Your name is ' + name) print('Your name is {}'.format(name)) print('Your name is %s' % (name,)) print(f'Your name is {name}') print('Your name is ', end='') print(name)
22nd Apr 2019, 5:21 AM
Anna
Anna - avatar
+ 4
Or you can do: print("\n".join(list_of_lines)) Or just using print: print(*list_containing_lines, sep="\n")
21st Apr 2019, 11:37 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 3
You can do it like this: print('Once upon a time ' 'there was this thing ' 'I call auto concat.') In output this will be just one line. For more details: https://code.sololearn.com/c9a0cG9dpVUr/?ref=app
21st Apr 2019, 10:59 PM
HonFu
HonFu - avatar
+ 1
Thanjs HF and Pro!
22nd Apr 2019, 12:49 AM
tristach605
tristach605 - avatar
0
Sorry? Where does it go exactly? cannot get it to work. Im trying to join between "named" "print(UNI)" and UNI = input("Welcome ") print(UNI) print("Dragon or Unicorn?") Drag_or_Uni = input("\nSo you chose ") print(Drag_or_Uni) print("Once upon a time there was a young unicorn named ") print(UNI) print(("Who lived in a magical forest. This world is yours to explore and the more answers you get correct the more powers you will have. Let's begin.....")) #Or you can do: #print("\n".join(list_of_lines)) #Or just using print: #print(*list_containing_lines, sep="\n")
22nd Apr 2019, 12:58 AM
tristach605
tristach605 - avatar