+ 3
You need to have more than one value argument in the print statement before it works, like this...... print(var_1, var_2, sep="_")
14th Sep 2024, 11:44 AM
Jan
Jan - avatar
+ 2
Naina Kapoor That's because you haven't created a var_2 with a value, but you can also just write... print(var_1, var_1, sep="_")
14th Sep 2024, 12:19 PM
Jan
Jan - avatar
+ 2
Naina Kapoor you must have more than 1 item to print, otherwise there is nothing to separate. print(1,2,3,4, sep='_') in your example, you are only printing var1
14th Sep 2024, 12:36 PM
Bob_Li
Bob_Li - avatar
+ 2
Naina Kapoor you can still use sep if you are just printing the result for a camel to snake conversion. def c2s(s): n=0 res=[] for i,e in enumerate(s): if e.isupper(): res.append(s[n:i].lower()) n = i res.append(s[n:].lower()) print(*res, sep='_') var = input().strip() c2s(var) s1 = 'weNeedToConvertToSnakeCase' c2s(s1)
15th Sep 2024, 5:21 AM
Bob_Li
Bob_Li - avatar
+ 1
We cannot see others code coach solution using the links.
14th Sep 2024, 11:18 AM
A͢J
A͢J - avatar
+ 1
Naina Kapoor sep will not work like that You have to use formatter like this f"_{var}" But you have to iterate string and check if a character is in upper case then use formatter to replace that character with _
14th Sep 2024, 11:27 AM
A͢J
A͢J - avatar
+ 1
Look at the difference: print("hello!, sep="_" ) #hello print("hello", "world", sep="_") #hello_world
14th Sep 2024, 7:34 PM
Ержан Базаргали
Ержан Базаргали - avatar
16th Sep 2024, 2:14 AM
A͢J
A͢J - avatar
+ 1
Naina Kapoor it's called slicing . it works for lists and strings to chop up parts you need.
16th Sep 2024, 6:35 AM
Bob_Li
Bob_Li - avatar