+ 3

Question for python 35.2

Hello everyone, ive been stuck on this question for quite a while can u guys help me out thanks! We are creating our own social network application and need to have a hashtag generator program. Complete the program to output the input text starting with the hashtag (#). Also, if the user entered several words, the program should delete the spaces between them. Sample Input code sleep eat repeat Sample Output #codesleepeatrepeat Hint You can use the replace() function to replace the spaces (" ") with empty strings (""). See how it works: s = input() def hashtagGen(text): #your code goes here text1= text.replace(text,"#"+"".join(text)) return text1 print(hashtagGen(s)) This is the code i use however, whenever the test case has words with a space, like space cat, the output will be #space cat instesd of the desired #spacecat

6th Apr 2021, 8:50 AM
Zhi Hong
Zhi Hong - avatar
7 Answers
+ 4
Try this buddy Used the hint for replace(), showing how it works then concatenated the # in the print statement. s = input() def hashtagGen(text): #your code goes here text1= text.replace(' ','') return text1 print('#'+ hashtagGen(s))
6th Apr 2021, 9:03 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 3
Benjamin JĂŒrgens ahh i see thank you for that Rik Wittkopp it works thank you!
6th Apr 2021, 9:46 AM
Zhi Hong
Zhi Hong - avatar
+ 2
s = input() def hashtagGen(text): text = s.replace(" ", "") return "#" + text print(hashtagGen(s))
13th Feb 2022, 5:15 PM
Abdikadir M Ainte
Abdikadir M Ainte - avatar
+ 1
Your second argument for the replace function is already close to a solution. There is only one misconception about how join works: The argument is treated as a list and the elements are joined by the string before join. A string as argument is treated as a list of characters, so it joins all characters with an empty string, returning an exact copy of the argument string. What you want as argument for join is a list of words. You can get that with text.split()
6th Apr 2021, 9:01 AM
Benjamin JĂŒrgens
Benjamin JĂŒrgens - avatar
0
s = input() def hashtagGen(text): #your code goes here text1=text.replace(" ","") return (text1) print("#"+hashtagGen(s))
30th Dec 2021, 10:43 PM
Shahad Al-Shama
0
s = input() s = "#"+s def hashtagGen(text): #your code goes here s1 = text.replace(" ","") return s1 print(hashtagGen(s))
5th Dec 2022, 4:02 AM
Noob X Neon
Noob X Neon - avatar
0
s = input() def hashtagGen(text): #your code goes here #replace method to the parameters & declare in a new variable text1 = text.replace(" ", "") #returns a new string return text1 #concatanation (#) on Output start print("#" + hashtagGen(s))
16th Apr 2023, 2:29 PM
AMINE MOUTAOUAKKIL