HW3, practice with python data types and syntax¶
This assignment reviews materials in lectures 4 and 5.
In all cases, programming should be done in python 3 and you should use any good programming practices that we have discussed so far (e.g. use of white space).
1. Data types¶
- Initialize a variable as a string which can be converted into a float, do so, and then print the number (with two decimal places) and object type that the variable points to.
In [ ]:
- Initialize variables pointing to the four types of collections discussed in class. Using comments, state two properties/features of each type of collection.
In [ ]:
- Create a list with the values 4, 9, 16, 25, 36, and 49 (in that order). Print 25, 36, 49, twice by using two different ways of indexing values. What happens when you index from a higher number to a lower number?
In [ ]:
2. Simple functions and logic¶
- Calculate a value from a formula of your choice that extends over two lines
In [ ]:
- Write a loop (whichever kind you wish) that creates a list containing the first 10 numbers in the Fibonacci sequence, where the first number is 0. Then, print the total of those 10 numbers and the final list.
In [ ]:
- Initialize a variable to point to a sentence of your choice. Check whether a word is contained within the string. If so, replace it with another word of your choice.
In [ ]:
- Predict the output from the following code block, then run it in python to check if you were correct: