0

What is the difference between these two programs: FROM module 3 final quiz, problem 2 and 4

def sum(x): res=0 for i in range(x): print(i) res +=i return res sum(10) and def sum(x): for i in range(x): print(i) return sum(10)

25th Sep 2016, 7:55 AM
Saurav Gupta
Saurav Gupta - avatar
1 Resposta
0
Hi, First your indentations are not correct and that prevent the code to run right. see following: def sum(x): res=0 for i in range(x): print(i) # for every number in range(x) NOT equal to i (item in the range) res +=i return res sum(10) OUTPUT: ~/Development/Python $ python solo1.py 0 ~/Development/Python ____________________________________ def sum(x): for i in range(x): print(i) return sum(10) OUTPUT: ~/Development/Python $ python solo2.py 0 1 2 3 4 5 6 7 8 9 ~/Development/Python
5th Oct 2016, 10:29 AM
Krasimir Vatchinsky
Krasimir Vatchinsky - avatar