| Both sides previous revisionPrevious revisionNext revision | Previous revision |
| public:t-vien-07-1:lab_1_materials [2008/01/09 17:06] – hannes | public:t-vien-07-1:lab_1_materials [2024/04/29 13:33] (current) – external edit 127.0.0.1 |
|---|
| |
| ===== In-Class Excercises ===== | ===== In-Class Excercises ===== |
| | |
| |
| |
| print mytuple[3][0] # Prints 7 | print mytuple[3][0] # Prints 7 |
| </code> | </code> |
| - Add the function **''fix''** to your program that takes in a single **''Item''** and forces its **''working''** value to **''True''**. Declare a list of names, called **''favorites''**, and instead of quitting after 10 failed attempts at using borrowed items, make the program fix all items possessed by those that have their name appear on the **''favorites''** list, but not the others. Print out the names of those that got their items fixed and let the program borrow a few more items to see if it can now continue it's habit a bit longer. \\ \\ <code python> | - Add the function **''fix''** to your program that takes in a single **''Tool''** and forces its **''working''** value to **''True''**. Declare a list of names, called **''favorites''**, and instead of quitting after 10 failed attempts at using borrowed tools, make the program fix all tools possessed by those that have their name appear on the **''favorites''** list, but not the others. Print out the names of those that got their tools fixed and let the program borrow a few more tools to see if it can now continue it's habit a bit longer. \\ \\ <code python> |
| # HINT: Finding matches between two lists | # HINT: Finding matches between two lists |
| listA = [1, 3, 5, 7, 9] | listA = [1, 3, 5, 7, 9] |
| print str(x)+" is common!" # Prints "5 is common!, 9 is common!" | print str(x)+" is common!" # Prints "5 is common!, 9 is common!" |
| </code> | </code> |
| - Instead of using the **''favorites''**, only fix items for those that exist in the online Símaskrá (http://www.simaskra.is). \\ \\ <code python> | - Instead of using the **''favorites''**, only fix tools for those that exist in the online Símaskrá (http://www.simaskra.is). \\ \\ <code python> |
| # HINT: Reading and parsing a source on the Internet | # HINT: Reading and parsing a source on the Internet |
| import urllib # Module for simple Internet sockets | import urllib # Module for simple Internet sockets |