## How do I square numbers?

A forum for general discussion of the Python programming language.

### How do I square numbers?

How can I write a program to calculating square numbers. The program should read a single line of input containing an integer, and print out the squares of all numbers up to and including that number.

Your program should work like this:

Example 1
Enter a number: 4
1 squared is 1
2 squared is 4
3 squared is 9
4 squared is 16

Example 2
Enter a number: 6
1 squared is 1
2 squared is 4
3 squared is 9
4 squared is 16
5 squared is 25
6 squared is 36
Last edited by Mekire on Mon Aug 19, 2013 9:03 am, edited 1 time in total.
Reason: Title changed; post locked.
el_manu

Posts: 87
Joined: Mon Aug 19, 2013 8:30 am

### Re: How do I square numbers?

You are going to need to post an attempt before you will receive much help. You need to get the input; loop through the numbers; and square and print each number.

-Mek
• Use code tags when posting code.
• Include any errors with your post (in code tags).
• Make examples the minimum length to demonstrate your issue.

Mekire

Posts: 1711
Joined: Thu Feb 07, 2013 11:33 pm
Location: Tucson, Arizona

### Re: How do I square numbers?

Code: Select all
`whileinputprint`

To calculate the square you can simply multiply the number with itself, but there is also a pow function.
Join the #python-forum IRC channel on irc.freenode.net!
Somelauw

Posts: 82
Joined: Tue Feb 12, 2013 8:30 pm

### Re: How do I square numbers?

Don't worry I did it:

Code: Select all
`a = int(input("Enter a number: "))for a in range(1, a+1):   print(a, "squared is", a**2)`

it was easy.
el_manu

Posts: 87
Joined: Mon Aug 19, 2013 8:30 am