''' DS2000 Fall 2024 Sample code from class - functions and scope! Takeaways: - function variables/parameters do not need to have the same names as when we call them - functions are independent, standalone mini programs - functions GET information via parameters - fuctions GIVE information via return ''' def process_lst(whole_str, long, lat): ''' parameters: string, two ints (positions) returns: list of strings, except at the two positions which are floats does: converst the string into a lis of strings, converts the list at the two given positions into floats ''' lst = whole_str.split(",") lst[lat] = float(lst[lat]) lst[long] = float(lst[long]) return lst def main(): # Step one: messing around with calling our function, and variable names # The function has a parameter whole_str. Can I do this? # Nope, whole_str is not defined :( # print(whole_str) # Let's call the function with some values whole_str = "ab,2.1,1.5" lat = 1 long = 2 # define a local function result, just empty string result = "" # NOW, can I do this becuase I have a local variable named whole_str print(whole_str) # the value in result changes because I called a function that returns something # whole_str, lat, long are the SAME names as what the function has result = process_lst(whole_str, long, lat) print(result) # Call the function again using different values a = "ls,3.4,8.6" x = 1 y = 2 result = process_lst(a, x, y) print(result) main()