0
What do I mean in this code?
def func(x): res=0 for i in range(x): res +=i return res print (func(x))
6 Answers
+ 2
For example: if you tpye 5 as the x. Because of the 'range' method, 'i' will be 0 1 2 3 4. 'res+=i' means 'res = res+i'. Because you have created the res=0, res=res+i will become res=0+0, res=0+1, res=1+2, res=3+3, res=6+4 so it returns the final res(equal 10).
+ 1
For example if you pass the 10 as the 'x' to the function 'i' will take all of the number from 0 to 9. However, because you have return yes(this bit will result in an error because yes isn't defined in python 2) the part of thw code that is under the l
5th line will never run.
+ 1
You need put a paramenter to print your function, for example: print(func(3)) the result is 5
+ 1
res is a variable that holds each number inside i that counts in the for loop up to the number you specify for x in range. Then as it counts it prints each one of those numbers out until it reaches the range limit, which is usually one less than the number in range.
0
i know that x in print should be a number but the quistion is still what is this part of code do exactly
0
@VonVerard, does i is mathmatical symbol like +,-,*âŠâŠâŠâŠ . and can i use it in any other code ???
and does i has a name like (plus + and divition /)????