+ 1
Can anyone explain how this works?😩
What ist the outcome of this Python Program and how does it work? a=7 a=int(input("enter a number:")) z=0 for i in range (0,a,1): z=z+a*i if i<5: for j in range (0, i+1,1): z=z+j print(str(z)) Thanks for help:)
1 Odpowiedź
+ 4
#First 2 variables are given a value
a = 7
z = 0
#Second a for loop is created to iterate through a range object from 0 to 7.
#In each iteration variable i is increased by 1.
for i in range(0, 7, 1):
#In the for loop z changes it's value with a certain logic.
#And if i is less than 5 an inner for loop is created, which iterates from 0 to i+1 and in each iteration it also changes z value with another logic.
The z value is
0
+7*0+0
+7*1+0+1
+7*2+0+1+2
+7*3+0+1+2+3
+7*4+0+1+2+3+4
+7*5
+7*6
z final value is 167