Homework:
Create a list of numbers and print every multiple of 3. Then, subtract 2 from every element and print every multiple of 3 from the changed list.
Use list comprehension to create a list of the square roots of every number from 0 to 10. Hint: square root = exponent of ½, so (9)**(1 / 2) = 3.
Create a coordinate plane using nested lists. It should look like this:
There is a tab between each element of each row.
Resources: Class slides: https://docs.google.com/presentation/d/1KZJiuDgLTRXbCrBTl7MoxMNUduLGNOvJqYCEviVlxMc/edit#slide=id.g13233bed446_0_1244 Class code: https://replit.com/@ShravyaS/IntroToPython-Class6#main.py Contact Info: shravyassathish@gmail.com (mentor) kingericwu@gmail.com (TA) felixguo41@gmail.com (TA)
Prompt 1:
my_list = list(range(20))
#print(my_list)
#print multiple of 3
for i in range(len(my_list)):
if(my_list[i] % 3 == 0):
print(my_list[i])
#change the list
for i in range(len(my_list)):
my_list[i] = my_list[i] -2
#print(my_list)
#print multiple of 3 a
for i in range(len(my_list)):
if(my_list[i] % 3 == 0):
print(my_list[i])
Prompt 2:
my_list = list(range(11))
print(my_list)
newlist = [x**(1/2) for x in my_list]
print(newlist)
x**(1/2)
Prompt 3:
for i in range(3):
# Append an empty sublist inside the list
for j in range(3):
my_list = [i, j]
print(my_list, end='\t')
print('\n')
1.
numbers = [2, 6, 8, 11, 16, 20, 23, 27]
for i in numbers:
if i % 3 == 0:
print(i)
for i in range(0, len(numbers)):
numbers[i] -= 2
if numbers[i] % 3 == 0:
print(numbers[i])
2.
numbers = [x**(1/2) for x in range(0, 11)]
print(numbers)
3.
for g in range(0, 3):
for h in range(0,3):
print(f"[{g}, {h}]\t", end="")
print("\n")
#1
list = [12, 3, 17, 234, 42, 2, 6, 4, 3, 54, 38]
for x in range(len(list)):
num = list[x]
if num % 3 == 0:
print(num)
list[x] -= 2
for x in list:
if x % 3 == 0:
print(x)
#2
list = [x**(1/2) for x in range (11)]
print(list)
#3
list = []
for x in range(3):
print('\n')
for y in range(3):
print([x, y], end = '\t')
nums = [7, 9, 9235, 3012, 36, 48, 742110, 401]
print(f"Part 1: (for reference, list is: {nums}")
for i in nums:
if i % 3 == 0:
print(i, end = " ")
for j in range(len(nums)):
nums[j] -= 2
if nums[j] % 3 == 0:
print("\n\n" + str(nums[j]))
roots = [k**(1/2) for k in range(1, 11)]
print("\n\nPart 2: " + str(roots) + "\n\n\nPart 3: ")
for m in range(8):
for n in range(8):
print(f"[{m}, {n}]", end = "\t")
print()