+ 4

How can I set this code so that don't go next line

morce_code = { "a" : ".-","b" : "-...","c" : "-.-.","d" : "-..","e" : ".","f" : "..-.","g" : "--.","h" : "....","i" : "..","j" : ".---","k" : "-.-", "l" : ".-..","m" : "--", "n" : "-.", "o" : ".--.", "p" : ".--.", "q" : "--.-", "r" : ".-.", "s" : "...", "t" : "-", "u" : "..-", "v" : "...-", "w" : ".--", "x" : "-..-", "y" : "-.--", "z" : "--..", " " : " " } text = input(" ") for char in text: morce = "" morce += morce_code[char] print(morce)

20th Feb 2023, 4:18 PM
Amirhossein Ghannad
12 odpowiedzi
+ 10
morce_code = { "a" : ".-","b" : "-...","c" : "-.-.","d" : "-..","e" : ".","f" : "..-.","g" : "--.","h" : "....","i" : "..","j" : ".---","k" : "-.-", "l" : ".-..","m" : "--", "n" : "-.", "o" : ".--.", "p" : ".--.", "q" : "--.-", "r" : ".-.", "s" : "...", "t" : "-", "u" : "..-", "v" : "...-", "w" : ".--", "x" : "-..-", "y" : "-.--", "z" : "--..", " " : " " } text = input() morce = "" for char in text: #morce = "" here this reset in iterations. morce += morce_code[char] print(morce) # after and outside loop. # is this way you are trying?
20th Feb 2023, 4:25 PM
Jayakrishna 🇮🇳
+ 3
Jayakrishna 🇮🇳 O yes It works Thank you so much again 💓
20th Feb 2023, 5:01 PM
Amirhossein Ghannad
+ 2
Code i posted printing in one line only. which code you are trying? What is your sample input and expected output....
20th Feb 2023, 4:46 PM
Jayakrishna 🇮🇳
+ 2
AmIraN gh Yes. Test the code which i posted above. It give you that expected output only.. The print( morce) i added after loop. Not inside. And morce declared before loop. Not inside loop.. Which code you are using ?
20th Feb 2023, 4:57 PM
Jayakrishna 🇮🇳
+ 1
Yap
20th Feb 2023, 4:29 PM
Amirhossein Ghannad
+ 1
Jayakrishna 🇮🇳 it goes next line again
20th Feb 2023, 4:44 PM
Amirhossein Ghannad
+ 1
I want print all morce code in one line
20th Feb 2023, 4:45 PM
Amirhossein Ghannad
+ 1
Jayakrishna 🇮🇳 My input is amir But it prints .- -- .. .-. I want it to print .- -- .. .-.
20th Feb 2023, 4:50 PM
Amirhossein Ghannad
0
How can
22nd Feb 2023, 7:21 AM
Sudeys abdu
Sudeys abdu - avatar
0
Sudeys abdu look at the best answer from Jayakrishna 🇮🇳
22nd Feb 2023, 7:35 AM
Amirhossein Ghannad
22nd Feb 2023, 7:37 AM
Amirhossein Ghannad