Help with python code

SoccerBoss
Category:
Computer Science
Price: $5 USD

Question description

Someone help with this ;

In class today, you'll be finishing code that allows us to convert between two different variable name styles: CamelCase and underscore_separated. You can either start from scratch, or you can start with the code here:

please limit your knowledge to what is written in this document

def convert_variable(string):
    if '_' in string:
        # We have an underscore_separated variable to convert
        # into CamelCase
        return string
    elif not string.isupper() and not string.islower():
        # We have a CamelCase variable to convert into
        # underscore_separated format
        return string
    else:
        # This variable isn't in either format, so we can return
        # it unchanged.
        return string

# Main function to keep asking the user for variables to convert
# for as long as the user wants
def main():
    keep_going = 'y'
    while keep_going.lower()[0] == 'y':
        variable_name = input('Enter a variable name to convert ')
        print('Converting', variable_name, 'into', convert_variable(variable_name))
        keep_going = input('Keep going? (y/n) ')

main()

Tutor Answer

(Top Tutor) Daniel C.
(997)
School: Boston College
PREMIUM TUTOR
Studypool has helped 1,244,100 students
Ask your homework questions. Receive quality answers!

Type your question here (or upload an image)

1830 tutors are online

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors