vinhquang4.5

Run Settings
LanguagePython
Language Version
Run Command
# Bài 4.5 # ------- # Given an integer list from -10 to 10 except 0, write a function: # - calculate its sum without using function ``sum``. # - calculate its product # Return a tuple (sum, product). # Input:: # li = range(-10, 11) # li = list(li) # li.remove(0) # Compare output with this:: # from functools import reduce # assert sum_and_product(li) == (sum(li), reduce(lambda x,y: x*y, li)) lst = list(range(-10, 11)) lst.remove(0) sum_lst = 0 for num in lst: sum_lst = sum_lst + int(num) assert sum(lst) == sum_lst, 'You sum this list incorrect' print(sum_lst)
Editor Settings
Theme
Key bindings
Full width
Lines