- 1
Returning from functions
Can you guys help me? 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:
4 Respostas
+ 3
1. Get the input and save it into a variable.
2. Make a function that takes the variable as a parameter. Inside the function use the replace() method to remove any spaces from the variable string that was input. Append a octothorp aka hashtag to the beginning of the string and return it from the function.
3. Call the function passing the input variable and print() its returned value.
Or don't make a function and just do it all inline.
+ 2
s = input()
def hashtagGen(text):
s1=text.replace(" ","")
return "#"+s1
print(hashtagGen(s))
We used + operator to add 2 strings.
0
Check this out;
s = input()
def hashtagGen(text):
# space is replace with no space""
s1 = s.replace(" ","")
return (print("#"+s1))
hashtagGen(s)