0

Question about i

Iā€™m brand new to programming and python. Just started yesterday. Iā€™m trying to under stand why in this code you set the i=0 total = 0 #your code goes here i=0 while i < 5: age= int(input()) i = i +1 if age < 3: continue total +=100 print (total)

21st Jan 2023, 4:32 PM
james ewell
james ewell - avatar
2 Answers
+ 2
OK FRIEND BECOURSE YOUR NEW TO PROGRAMING I WILL EXPLAIN THIS WHOLE CODE AS SIMPLE I CAN total = 0 """here total is a variable which is assigned value is zero, variable is a container that we can store data( actually it is store in computer memory ) """ #your code goes here i=0 """ here also i is a variable which is assigned 0 """ while i < 5: """ while is a loop function which we can iterate some particular code or codes in side of while loop until fulfil some condition or conditions here the condition is i<5 that means this while loop is iterating till i less than 5 """ age= int(input()) """ here program looking for user input (data) , after getting the data its convert to integer 'int()' then the value is assign to age veriable """ i = i +1 """ here the value of i is increase by 1 """ if age < 3: """ here if age is less than 3 then execute continue statement """ continue """ here the continue statement dose is go to the initial point of our while loop without executing other statements in while loop below the continue statement """ total +=100 """here total variable increase by 100 """ print (total) """ here print statement is out side of the while loop so after i value equal to 5 then print statement will print the value of total to the console """
21st Jan 2023, 6:18 PM
Thilina Dajahetti
Thilina Dajahetti - avatar
0
Thank you so much!
21st Jan 2023, 5:40 PM
james ewell
james ewell - avatar