# Putting outputs of calculations into a table

Page 1 of 1

## 5 Replies - 484 Views - Last Post: 04 October 2011 - 08:07 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=249434&amp;s=14e6b491fd9db338623f11d1d3d9b4e4&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 krajand14

Reputation: 0
• Posts: 19
• Joined: 01-October 11

# Putting outputs of calculations into a table

Posted 01 October 2011 - 08:03 PM

Hi, I am trying to do some calculations then, after they are done, print the outputs of each into a table for readability. My problems arises that i do not know how to do this.

```x = raw_input('What is the starting value of x:')
x = float(x)

y = raw_input('What is the starting value of y:')
y = float(y)

N = raw_input('How many times do you want the code executed:')
N = int(N)

Dx = raw_input('By how much do you want the parameter x to vary each run:')
Dx = float(Dx)
Dy = raw_input('By how much do you want the parameter y to vary each run:')
Dy = float(Dy)

print '---------------parameters------------------'
print 'The initial values are: x = ',x,'; y = ',y
print '---------------Step Values-----------------'
print 'The step value for x is Dx = ',Dx,' for y it is Dy = ',Dy
print '-----------------N Value-------------------'
print 'The program will be executed', N,'times'

count = 1
RMS_error = ''

#RMS error calculation
#RMS error = sqrt(((x**2)-(y**2))/count)

if x <= y:
print 'RMS error is not valid'

if x > y:
# The following lines print out the values after each run
while count <= N:
RMS_error = math.sqrt(((x**2)-(y**2))/count)
print '--------------RMS Error-------------'
print 'Error = ', RMS_error,'After',count,'runs'

count += 1
if count == N:
print 'end program'
print 'final x = ',x,'final y = ',y
break
x = x + Dx
y = y + Dy

print '--------------New values------------'
print 'new x = ',x,'new y = ', y
```

Is This A Good Question/Topic? 0

## Replies To: Putting outputs of calculations into a table

### #2 zem107

Reputation: 7
• Posts: 84
• Joined: 10-April 11

## Re: Putting outputs of calculations into a table

Posted 01 October 2011 - 08:43 PM

first of all, for getting input for floats
do not use
```x = raw_input('What is the starting value of x:')
x = float(x)

```

use
```x = float(input('What is the starting value of x: '))

```

and for integers use
```N = input()
```

it just makes it easier and shorter.

And for all your math and square root operations, you need to import math first by doing this
```import math
```

This line should be anywhere before you use the functions, prefereably in the beginning of your file.

And I never got around to running your code so can you please tell what error you are getting.

### #3 krajand14

Reputation: 0
• Posts: 19
• Joined: 01-October 11

## Re: Putting outputs of calculations into a table

Posted 01 October 2011 - 09:16 PM

im not getting any error I just want to be able to print the values of the output into a table of different rows and columns

### #4 zem107

Reputation: 7
• Posts: 84
• Joined: 10-April 11

## Re: Putting outputs of calculations into a table

Posted 01 October 2011 - 09:35 PM

Oh okay, I'm kinda sleepy right now, and I'm kind of busy also.

### #5 baavgai

• Dreaming Coder

Reputation: 6297
• Posts: 13,461
• Joined: 16-October 07

## Re: Putting outputs of calculations into a table

Posted 02 October 2011 - 05:50 AM

This should work:
```def doCalcuation(x,y, Dx, Dy, N):
print '---------------parameters------------------'
print 'The initial values are: x = ',x,'; y = ',y
print '---------------Step Values-----------------'
print 'The step value for x is Dx = ',Dx,' for y it is Dy = ',Dy
print '-----------------N Value-------------------'
print 'The program will be executed', N,'times'

if x <= y:
print 'RMS error is not valid'
else:
count = 1
# The following lines print out the values after each run
while count <= N:
# this does not return an error, it returns a result
# what are you doing here???
# RMS_error = math.sqrt(((x**2)-(y**2))/count)
# print '--------------RMS Error-------------'
# print 'Error = ', RMS_error,'After',count,'runs'

# you defined the check this in the while...
# count += 1
# if count == N:
# what are you doing here?
# print 'end program'
# print 'final x = ',x,'final y = ',y
# break
x = x + Dx
y = y + Dy

# now that you've left the loop, print this
print 'end program'
print 'final x = ',x,'final y = ',y
# this is kind of silly at this point
# print '--------------New values------------'
# print 'new x = ',x,'new y = ', y

```

As for input, look into try except for when they don't enter a float or an int.

Hope this helps.

### #6 zem107

Reputation: 7
• Posts: 84
• Joined: 10-April 11

## Re: Putting outputs of calculations into a table

Posted 04 October 2011 - 08:07 PM

Sorry I couldn't get back to you, I was sick, but baavgai seems to have good code, you should probably look through his.