this function appends n elements to list. The function is required to modify the original list and return None I don't know whats wrong here: def appendn(lst, n, elem): for i in range(n): lst = lst.append(elem) list1 = ['w', 'o', 'o', 'h'] list2 = [] try: appendn(list1, 3, 'o') appendn(list2, 10, 0) except: pass test cases: list1 ['w', 'o', 'o', 'h', 'o', 'o', 'o'] appendn([1, 2, 3], 10, 0) None list2 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
It's 2 debug questions (ALL IN PYTHON PROGRAMMING)
this function appends n elements to list. The function is required to modify the original list and return None
I don't know whats wrong here:
def appendn(lst, n, elem):
for i in range(n):
lst = lst.append(elem)
list1 = ['w', 'o', 'o', 'h']
list2 = []
try:
appendn(list1, 3, 'o')
appendn(list2, 10, 0)
except:
pass
test cases:
list1 | ['w', 'o', 'o', 'h', 'o', 'o', 'o'] | ||
appendn([1, 2, 3], 10, 0) | None | ||
list2 | [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] |
Another question, I suppose to draw a snowflake using this function, but everytime I get to the "whole" part when I put part 1,2,3 together, python tells me that I'm getting Syntax errors.
def snowflake():
part1 = kochize(5)
part2 = rotate(2*(pi/3))(kochize(5))
part3 = rotate((-2*(pi/3))(kochize(5))
whole = connect_ends((part1, part2), part3)
return whole
I don't understand why am I getting syntax errors with line5 of this function.
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images