+ 4

Why sep parameter isn't working here in python problem

Question: https://www.sololearn.com/coach/82?ref=app Answer body : var = str(input()) var_1 = var.lower() print (var_1 , sep = "_")

14th Sep 2024, 11:15 AM
Himawari
Himawari - avatar
15 ответов
+ 3
---> sep Issue: sep doesn't do anything here because you're only dealing with one string, not multiple values to separate. ----> Conversion Logic Missing: Your code should include steps to insert underscores before uppercase letters and turn those letters into lowercase. https://www.sololearn.com/discuss/3291612/?ref=app def camel_to_snake(camel_str): result = [] for char in camel_str: if char.isupper(): if result: result.append('_') result.append(char.lower()) else: result.append(char) return ''.join(result) var = input().strip() print(camel_to_snake(var))
15th Sep 2024, 3:41 AM
AstroSakura さくら 🌸
AstroSakura さくら 🌸 - avatar
+ 4
Programming is very dangerous 💀 I'm too beginner for this question 😤🥺 however Muhammad Nouman Ali , A͢J ,Jan ,Bob_Li , and Ержан Базаргали thanks alot for your helpful support 🥰
15th Sep 2024, 4:38 AM
Himawari
Himawari - avatar
+ 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
+ 3
A͢J can please share the sample code 🙂🙏
14th Sep 2024, 12:04 PM
Himawari
Himawari - avatar
+ 3
Bob_Li I'll surely implement this 🥰 but at first I would learn the concept to understand what functions and methods you've used in this program ☺️ your support is really appreciable and I'm grateful for your help 🙏💖
16th Sep 2024, 6:12 AM
Himawari
Himawari - avatar
+ 2
A͢J bhaiya I've inserted the answer below of the question
14th Sep 2024, 11:20 AM
Himawari
Himawari - avatar
+ 2
Jan it is not working 😭😭
14th Sep 2024, 12:04 PM
Himawari
Himawari - 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