▲ 2 r/cs50
PSET-2 of CS50p. Camelcase and snakecase
Ive recently started cs50p. im currently in my last year of junior high and going to grade 11 next year. Im very very new to coding and to be frank i have very poor problem solving skills. I have been stuck on this code for 2 days now and i cant seem to figure it out. This is my code:
# Make a main() function where i ask for the str from user in camel case
def main():
string = input("camelCase: ")
print("snake_case: ", snake_case(string))
# Now i make the snake case function
def snake_case(given):
# Make a for loop for the characters in the given str
for chars in given:
# If chars is lowercase, keep the chars unchanged
if chars.islower():
lowerchars = str(chars.lower())
# for uppercase chars in str, return _ followed by the chars in lowercase
if chars.isupper():
upperchars = str("_".join(chars.lower()))
# Now add the lowercase and uppercase chars together
return lowerchars + upperchars
u/InSaNe72 — 17 hours ago