main function scope issues - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: main function scope issues (/thread-12521.html) |
main function scope issues - wak_stephanie - Aug-29-2018 I created a Python function that take an argument, full name, gets full name's initials and prints them out capitalized but the problem is with my main function I believe at the end of the code in terms of being a global scope vs local scope... I could be wrong though. Any help is appreciated imports get_initials """ Given a person's name, returns the person's initials (uppercase) """ # TODO your code here def get_initials(fullname): fullname.split() name_list = xs.split() print(name_list) get_initials = input("What is your full name?") initials = "" def main(): for name in name_list: # go through each name initials += name[0].upper() # append the initial return intials if__name__ == '__main__': print: initials main()[error]invalid syntax (initials.py, line 16) RE: main function scope issues - Larz60+ - Aug-29-2018 1. Indentation is messed up 2. A script doesn't import itself 3. you haven't defined name_list 4. Misspelled initials on return line 5. a bunch more """ Given a person's name, returns the person's initials (uppercase) """ # TODO your code here def get_initials(fullname): name_list = fullname.split() print(name_list) initials = "" # the code below was moved here. if in main, name_list would have been out of scope. for name in name_list: # go through each name initials += name[0].upper() # append the initial return initials def main(): return get_initials(input("What is your full name?")) if __name__ == '__main__': print(main()) |