5 Replies - 322 Views - Last Post: 04 October 2011 - 08:07 PM Rate Topic: -----

#1 krajand14  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#3 krajand14  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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
Was This Post Helpful? 0
  • +
  • -

#4 zem107  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • 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.
I might answer your question tomorrow or day after.
Was This Post Helpful? 0
  • +
  • -

#5 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5643
  • View blog
  • Posts: 12,359
  • 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.
Was This Post Helpful? 0
  • +
  • -

#6 zem107  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1