Python Operators and Lists Completed Version
Python Operators and Lists Completed Version
11 % 3 = 2, 23%10 = 3
1. Python operators work the way you would expect. You should also be familiar with
modulus which uses the percentage sign. Explain how to find modulus and answer the
following: Example 17%3 = 2, 19%4 = 3
a. 12 % 3 = 0
b. 11 % 2 = 1
c. 27 % 10 =7
d. 30 % 4 =2
2. It is also useful to understand the following and be able to answer the following if x = 4
what does x equal after the expression is done: eg.
X *= 4 x = x * 4
Examples x - = 1 means x = x -1 answer is 3
x*=4 means x = x times 4 x will equal 16
x/=1 means x = x / 1 equals 4
X *= 7 x = x* 7 x = 28
a. x %=3 means x = x%3
b. x += 3 means x = x + 3 7
c. x*=5 means x = x times 5
d. x/=2 means x = x / 2
e. x**3 ** meansx “to the power of “3
x*=2 x = x *2 x = 8
3. Lists in Python are similar to arrays in Java and Javascript. See this link :
https://www.w3schools.com/python/python_lists.asp Create a new python program
called CreateLists. In this program create 3 lists and use the information on the link
https://www.geeksforgeeks.org/print-lists-in-python-4-different-ways/ to print the items
without using a loop and with a space. Also print the length of each list with a command
like : print("The length of the list is "+ str(length)). You should have one list of Strings
with 5 items, one list of numbers with 10 items, and one list with a mix of numbers and
strings with 8 items.
4. Remove the “str” in the command to print the length of the list and run it to check what
happens. In the print command for length, why did we have to use casting?
5. Create another Python program called UsingListItems. In this program create a list of 6
String values called SixStrings. Create another list called eightNums. Use these lists to
demonstrate the following. Add comments to show what you are doing. Check the
following link that explains how to do each of the following.
https://www.w3schools.com/python/python_lists.asp
a. Print the third value from SixStrings list
b. Add an item to SixStrings and then print it.
c. Two methods of removing an item from SixStrings and print it each time
d. Loop through eightNums adding 9 to each number and then print it. (Check how
to do a while loop here:
https://www.w3schools.com/python/python_while_loops.asp