Homework
1. Print a pattern where the first row has one A, second row two Bs, third row three Cs, etc.
A
B B
C C C
D D D D
E E E E E
(so on and so forth)
2. Print a pattern where the first row has A, second row has B C, third row D E F, etc.
A
B C
D E F
G H I J
K L M N O
(so on so forth)
Hint: you’ll need an additional variable outside the for loops for the index of string of letters.
3. Create a list of numbers, then use a for loop to multiply all the elements. Next, append a new element while removing a different old one, and then repeat the process of multiplication. Print both products.
Resources:
Class slides: https://docs.google.com/presentation/d/1ML3hll2J9nWQNLFKON2JHnkiJnzUpEy9uPNKTluMnD0/edit?usp=sharing
Class code: https://replit.com/join/qlpoayfbyz-shravyas
Contact Info:
shravyassathish@gmail.com (mentor)
kingericwu@gmail.com (TA)
felixguo41@gmail.com (TA)
letters = ["A","B","C","D","E","F","G","H","I"]
num = len(letters)
nub = 0
for i in range(num):
for j in range(i+1):
print(letters[nub], end = " ")
print("\n")
nub+=1
letters = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","DONE"]
nub=0
for i in range(len(letters)):
for j in range(i+1):
if nub<=int(25):
print(letters[nub], end = " ")
nub+=1
print("\n")
Prompt 1:
import string
alphabet = list(string.ascii_uppercase)
for l in alphabet:
count = ord(l) - ord('A') + 1
for i in range(0, count):
print(l + " ", end=''),
print("")
Prompt 2:
import string
alphabet = list(string.ascii_uppercase)
index_newline = 0
index_inc = 1
for i in range(0,26):
print(alphabet[i],end='')
if(i == index_newline):
print("")
index_inc = index_inc + 1
index_newline = index_newline + index_inc
Prompt 3:
def my_multiply(list):
prod = 1;
for i in old_list:
prod = prod * i
return prod
old_list = [2, 3, 5, 7]
print(my_multiply(old_list))
old_list.append(11)
old_list.remove(7)
print(my_multiply(old_list))
1.
letter=["A","B","C","D","E","F","G","H","I", "J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
x=26
for i in range(x):
for j in range(i+1):
print(letter[i], end= " ")
print("\n")
2.import string
letter = string.ascii_uppercase
start = 0;
end =25;
current =-1;
for i in range(10):
for j in range (i+1):
current = current+1;
if(current > end):
break;
print(letter[current], end= " ");
if (current >= end):
break;
print("\n");
3.x=1
lisq=[1,2,3,4,5,6]
for i in range(6):
x=lisq[i]*x
print(x)
print("\n")
lisq.append(7)
lisq.remove(4)
x=1
for i in range(6):
x=lisq[i]*x
print(x)
print("\n")
1.
l = ord('A')
for i in range(1, 27):
print(chr(l)*i)
l = l+1
2.
l = ord('A')
for i in range(1, 27):
for j in range(0, i):
print(chr(l), end=" ")
l = l + 1
if (l > ord('Z')):
break
print("")
if (l > ord('Z')):
break
print("")
3.
numbers = [4, 5, 61, 89, 74, 24, 9, 7, 80]
result = 1
for i in numbers:
result = i * result
print(result)
numbers.append(45)
numbers.remove(5)
result = 1
for i in numbers:
result = i * result
print(result)
nums = [42, 9, 37, 79, 9, 5049, 9711]
print(f"\n\nPart 3: The... Array. (For reference, the original list of numbers is: {nums})\n\n")
o = 0
for m in nums:
nums[o] = nums[o]*54
o += 1
print(nums)
nums[4] = 7
o = 0
for n in nums:
nums[o] = nums[o]*(1/6)
o += 1
print(nums)
ALLPHABET = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
for i in range(26):
print((ALLPHABET[i] + " ")*(i+1))
l = 0
for j in range(8):
for k in range(j):
if l <= 25:
print(ALLPHABET[l], end=" ")
l += 1
print()
ALLPHABET = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
print("Part 1: the AlphaPyramid")
for i in range(26):
print((ALLPHABET[i] + " ")*(i+1))
print("\n\nPart 2: the AlphaAlphaPyramid\n")
l = 0
for j in range(8):
for k in range(j):
if l <= 25:
print(ALLPHABET[l], end=" ")
l += 1
print()
nums = [42, 9, 37, 79, 9, 5049, 9711]
print(f"\n\nPart 3: The... Array. (For reference, the original list of numbers is: {nums})\n\n")
o = 0
for m in nums:
nums[o] = nums[o]*54
o += 1
print(nums)
nums[4] = 7
o = 0
for n in nums:
nums[o] = nums[o]*(1/6)
o += 1
print(nums)