Computer Science, asked by purveshKolhe, 4 months ago

num = int(input())
sum = 0
factors = []
for i in range(1 , num+1):
if num%i == 0:
factors.append(i)
sum +=i



What is the output? Java..​

Answers

Answered by allysia
8

It aint JAVA brav it's Python.

Correction the indentations:

num = int(input())

sum = 0

factors = []

for i in range(1 , num+1):

if num%i == 0:

factors.append(i)

sum +=i

What its doin here?:

  • num takes in a number.
  • sum initialized to 0
  • factor list initialised.
  • with for loop you check if the number is divisible by the numbers in the range of 1 to the number itself inclusively. (basically looking for factors)
  • if yes you're adding it to your list and summing the number in the variable.

Output?:

No Output.

Why?

Because there is nothing that printing the value of sum or the factor list on the screen.

Add print(sum) in the next line to the last program line and you will get an output depending upon the value you've entered.

For 1 output will be 1

for 2 it'll be 3 (1+2)

for 3 it'll be 4 (1+3)

for 4 it'll be 7 (1+2+4)

for 5 it'll be 6 (1+6)

and so on.

Answered by sejal13709
1

Answer:

Explanation:

sum = 0

factors = []

for i in range(1 , num+1):

if num%i == 0:

 hey.......!

are u maharashtrian?????

 means are Marathi

Similar questions