![]() |
|
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Hobbyist Programmer
Join Date: Mar 2005
Posts: 148
Rep Power: 4
![]() |
How would I do this in Python?
I've written this program both in Java and in C++, so now I'm trying to do it in Python. All the program does is use a loop from 1 to 5 and output each number followed by that number squared. It outputs the numbers in columns, so it needs to look like this:
Value Square 1 1 2 4 3 9 4 16 5 25 Here is all I got so far: def square(x):
return x * x
print "Value Square"
for i in range(1, 6):
print i + " " + square(i)But of course it's wrong cuz the compiler tells me I can't concatanate and integer with " ". I'm looking for some way to tell the compiler to first print the value of i then move over to the next column, and print that value squared. Then after that, move to the next line and do the same for the next value of i. Last edited by 357mag; Jul 6th, 2007 at 9:43 PM. Reason: mistake |
|
|
|
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Beginers Python Tutorial | Beegie_B | Python | 15 | Jul 28th, 2006 11:43 AM |
| [tutorial] Python for programming beginners | coldDeath | Python | 30 | Dec 14th, 2005 11:35 AM |
| Convert Python script to C++ code | clanotheduck | Python | 17 | Sep 25th, 2005 8:55 AM |
| Advanced Python Tricks | Arevos | Python | 19 | Sep 24th, 2005 7:39 AM |
| Python - A Programmers Introduction | coldDeath | Python | 17 | Aug 19th, 2005 12:41 PM |