Difference between revisions of "CompSciHW1"
From Predictive Chemistry
(Created page with "Homework 1 (due Wednesday, Jan. 20, 2016) Use the 7 forms to write code performing the following: # Create a variable named '''x''' holding the string "Hello World!" # Creat...") |
|||
Line 1: | Line 1: | ||
− | Homework 1 (due |
+ | Homework 1 (due Monday, Jan. 25, 2016) |
Use the 7 forms to write code performing the following: |
Use the 7 forms to write code performing the following: |
Latest revision as of 08:56, 13 January 2016
Homework 1 (due Monday, Jan. 25, 2016)
Use the 7 forms to write code performing the following:
- Create a variable named x holding the string "Hello World!"
- Create a (length 8) list containing the pattern below:
- 3 8 15 24 35 48 63 80
- Each element should use an arithmetic expression (calculator form).
- assign the list to the variable y
- Print a greeting displaying the variable x followed by element 4 of the list above.
- Assign the variable z to element 4 of y if element 4 of y is larger than 42. Otherwise, set z equal to element 5 of y.
- Call the function x.__add__ with one argument, " World! World!".
- Re-write your answer to the last question by sending a variable as an argument, instead of directly writing "World! World!".
- Write a description of what the following program does.
- How would you modify the code to eliminate all the i = len(x)-1 lines?
- Re-write the code, abstracting out the numbers 61 and 900 into variables a and m.
<source lang="python"> x = [541] i = len(x)-1 x.append(x[i]*61 % 900) i = len(x)-1 x.append(x[i]*61 % 900) i = len(x)-1 x.append(x[i]*61 % 900) i = len(x)-1 x.append(x[i]*61 % 900) i = len(x)-1 x.append(x[i]*61 % 900)
print len(x) print x </source>