Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- job_opening = ("Software Engineer", "New York City", 100000)
- position, city, salary = job_opening #destructuring values in job_opening tuple and assigning them to new variables
- #Testing
- print(position)
- print(city)
- print(salary)
- address = ("35 Elm Street", "San Francisco", "CA", "94107")
- street, *city_and_state, zip_code = address #destructuring values in address tuple and assigning them to new variables
- #Testing
- print(street)
- print(zip_code)
- print(city_and_state)
- #This program declares a function that accepts a tuple of elements(numbers) and returns a tuple with two numeric values: (sum of the even numbers, sum of the odd numbers)
- #function
- def sum_of_evens_and_odds(*a_tuple_of_numbers): #asterisks(*) should be introduced to demonstrate that it would accept a tuple
- even_numbers = sum(tuple(filter(lambda x : x%2 ==0 , a_tuple_of_numbers))) #this would store the sum of all the even numbers in the tuple in the even_numbers variable
- odd_numbers = sum(tuple(filter(lambda x : x%2 ==1 , a_tuple_of_numbers))) #this would store the sum of all the odd numbers in the tuple in the odd_numbers variable
- return(even_numbers, odd_numbers)
- #calling the function
- print(sum_of_evens_and_odds(1, 2, 3, 4)) # Example (the argument must be a tuple consisting of numbers)
- print(sum_of_evens_and_odds(2, 4, 6)) # Example
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement