Help with python code

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
        # 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) ')


Tutor Answer

(Top Tutor) Studypool Tutor
School: Duke University
Studypool has helped 1,244,100 students
flag Report DMCA
Similar Questions
Hot Questions
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