Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to sum all the answers from for loop?

Well I’m quite new to python and I’m struggling with this at the moment. I need to sum up all the answers(returns) from this for loop but I don’t really know how to do this.

a = int(input('Enter a number plz '))
for i in range(1, a+1):
    def func(root):
        print('Number', i, 'in square root is', root)
    func(i*i)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The next code should solve a problem:

a = int(input('Enter a number plz '))
s = 0
for i in range(1, a+1):
    def func(root):
        print('Number', i, 'in square root is', root)
        return root
    s += func(i*i)
print("The sum is " + str(s))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading