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 calculate square root of natural numbers upto a given number

I have to take input of an integer and then print the squares of all natural numbers upto that number.
I am doing following:

x=input("enter the integer")
for i in range(1,x):
 print(i*i)

I am getting errors in it. please help

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

>Solution :

Whenever you take input in python it treats it as a string not int, so you need to specify that in code, also you have range from (1,x); it will exclude x hence take x+1

x=int(input("enter the integer"))
for i in range(1,x+1):
 print(i*i)

please let me know if it worked properly

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