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

# Putting outputs of calculations into a table

Page 1 of 1## 5 Replies - 611 Views - Last Post: 04 October 2011 - 08:07 PM

### #1

# 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.

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

### #2

## 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

use

and for integers use

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

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.

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

## 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

## 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.

I might answer your question tomorrow or day after.

I might answer your question tomorrow or day after.

### #5

## Re: Putting outputs of calculations into a table

Posted 02 October 2011 - 05:50 AM

This should work:

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

Hope this helps.

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

## 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.

Page 1 of 1