Help with python code

avpubynfXvz
timer Asked: Nov 8th, 2015

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()

User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

This question has not been answered.

Create a free account to get help with this and any other question!

Related Tags

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