Homework:
Using nested for loops, print a triangle with this pattern:
*
* * * *
* * * * * * * * *
* * * * * * * * * * * * * * * *
Create a list. Using a while loop, keep taking user input, and add the input to a list until the user enters “STOP”. Then, print all the elements of the list backwards, spaced with a tab.
Iterate through a loop of positive and negative integers. If the element is positive, append it to a new list. Print the new list.
Use either for i in listName or for i in range(len(listName))
Resources:
Class slides: https://docs.google.com/presentation/d/1sOa_dL0L5SY4MS3t7HqVnIOU-PW4F9Ze_ZOgh0ySVmQ/edit?usp=sharing
Code: https://replit.com/@ShravyaS/IntroToPython-Wk3Day1#main.py
To view the code, open the link, and on the top left of the box, there is a button to show files. Click that and then click on main.py. If I got something wrong or it doesn't work send me a screenshot and I'll figure it out.
Coding platform: replit.com
Post your answers as a comment! I will post the solution before next class.
You can always email us at shravyassathish@gmail.com (mentor) or kingericwu@gmail.com (TA) or message us on Discord if you have any questions about the homework or what we covered in class.
for i in range(1,5):
for j in range(1,i**2 + 1):
print("* ", end = "")
print("\n")
list1 = []
while True:
input1 = input("enter a string: ")
if input1 == 'stop':
break
list1.append(input1)
list1.reverse()
print('\t'.join(list1))
list2 = [1,2,3,-4,5,6,-7,8,-9,-5]
list3 = []
for i in list2:
if i > 0:
list3.append(i)
for j in list3:
print(j, end = '')