The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | May 2017 |
| Last Sign in: | 399 Weeks Ago, 1 Day Ago |
| Questions Answered: | 66690 |
| Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
Function Name:offset
Description:Write a function called offset that indexes into two tuples and returns a tuple. The return tuple will contain,in order, the indices visited. The following are the rules for how you should visit an index:
1. Visittuple_1atindex_1(a parameter).
2. Store the visited index.
3. Visittuple_2at the stored index from step 2.
4. Store the visited index.
5. Repeat steps 1 - 4
6. Stop whenever you reach an index of 0 in either of the two tuples.
Remember to store every index that you visit, includingindex_1(the starting index) and 0 (the ending index), and return those values in a tuple.
To better represent this say we have tuple_1: (3,2,1,0) and tuple_2: (0, 1, 2, 3). The element at index 0 for tuple_1 is 3. This 3 now represents the number which you will use to index into tuple_2. tuple_2 at index 3 is 3. This 3 now represents the number which you will use to index into tuple_1. tuple_1 at index 3 is 0. So now you will stop. The path that you return is: (0, 3, 3, 0)
Parameter(s):
tuple_1: A tuple of integers. Each integer is a valid index for theothertuple.
tuple_2: A tuple of integers. Each integer is a valid index for theothertuple.
index_1: A single integer. The index of where to begin the path in thefirst
tuple.
Return Value:A new tuple with the path to 0.
Assumption(s):
The integers in both of the tuples are unique.
The integers correspond to actual indexes of the other tuple.
The integer indices will not result in an endless loop.
Once one of the indices is a 0, you can stop.
Example(s):
>>> number_tuple_1 = (6,4,2,7,1,9,3,5,8,0)
>>> number_tuple_2 = (3,8,1,0,9,6,5,4,7,2)
>>> index_1 = 4
>>> print(offset(number_tuple_1, number_tuple_2, index_1)) (4, 1, 8, 8, 7, 5, 6, 3, 0)
CS 1301 – Homework 5: Tuple and Dictionary Manipulation – Fall 2016
Hel-----------lo -----------Sir-----------/Ma-----------dam----------- Â----------- Th-----------ank----------- Yo-----------u f-----------or -----------usi-----------ng -----------our----------- we-----------bsi-----------te -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill-----------