15,168,423 members
1.00/5 (1 vote)
See more:
Hey, I keep getting an error for my program and I just can't figure it out.
It's for the table part

This program is meant to find the time and avarage times for an experiment

When i don't use a function its fine, but when i do it isnt.

Python
```import pylab as pyl
import numpy as np
import sys
print 'Times, Average Times, Velocity'

tteb=np.zeros((3,7),dtype=float)
pos=np.zeros((1,7),dtype=float)

for r in range (0,7):
print 'Band Position %d'%r
pos[0,r]=float(raw_input('~'))
posp=pos*(5.16667*10**(-4))

for j in range (0,3):
k=j+1
print 'This is for trial %d' %k
for i in range (0,7):
print 'Input for band %d'%i
tteb[j,i]=float(raw_input('~'))
print 'Trials 1-3 for all 7 bands.:'
print tteb

raw_input('Press [Enter] to continue to average time and *velocity *(later).')

ttebatvsum=tteb.sum(axis=0)
print 'This is all the times added together. (Bands 0--->6).'
print ttebatvsum
print 'This is the average for all of the times. (Bands 0--->6).'
ttebatvmean=ttebatvsum/3
print ttebatvmean
raw_input('Press [Enter] to continue to velocity.')
velocity=posp/ttebatvsum
print 'Here are all the velocities. (Bands 0--->6).'
print velocity

#Table here
def table():
print 'Pos (ml) |Pos (m)  |t1       |t2       |t3       |t(avg)   |v        |'
for k in range (0,7):
print '%-8.3f |%-8.3f |%-8.3f |%-8.3f |%-8.3f |%-8.3f |%-8.3f |'%(pos[k],posp[k],tteb[0,k],tteb[1,k],tteb[2,k],ttebatvmean[k],velocity[k])
raw_input('Press [Enter] to see graph. Please note that graph will be opened in a new window.')

#Graph here
def graph():
ttebatvcumsum=ttebatvsum.cumsum()
x=ttebatvcumsum
y=velocity
pyl.plot(x,y)
pyl.xlabel('Cumalative Time from release of Sphere, t')
pyl.ylabel('Velocity, v')
pyl.show()

def nextfunc(whattheysaid):
option1=set(['y','yes','yeah','okay','ok','cool','mmmhhhmmm'])
option2=set(['n','no','kys','obviously not','nope','dont disturb me'])
keepgoing=whattheysaid
if keepgoing in option1:
table()
graph()
elif keepgoing in option2:
print 'Exiting now!'
sys.exit()
else:
print 'Please reply with yes or no. This program will now exit.'
sys.exit()

print 'Hey so now that youre done with that stuff, want to see the table and graph?'
nextfunc(user_input)```

the part which doesnt work is

Python
```def table():
print 'Pos (ml) |Pos (m)  |t1       |t2       |t3       |t(avg)   |v        |'
for k in range (0,7):
print '%-8.3f |%-8.3f |%-8.3f |%-8.3f |%-8.3f |%-8.3f |%-8.3f |'%(pos[k],posp[k],tteb[0,k],tteb[1,k],tteb[2,k],ttebatvmean[k],velocity[k])
raw_input('Press [Enter] to see graph. Please note that graph will be opened in a new window.')```

and the error is

```Traceback (most recent call last):
File "C:\Users\Looi\Desktop\Stuff\School\ICT\Term 2\Python\Coursework\q5.py", line 84, in <module>
nextfunc(user_input)
File "C:\Users\Looi\Desktop\Stuff\School\ICT\Term 2\Python\Coursework\q5.py", line 73, in nextfunc
table()
File "C:\Users\Looi\Desktop\Stuff\School\ICT\Term 2\Python\Coursework\q5.py", line 55, in table
print '%-8.3f |%-8.3f |%-8.3f |%-8.3f |%-8.3f |%-8.3f |%-8.3f |'%(pos[k],posp[k],tteb[0,k],tteb[1,k],tteb[2,k],ttebatvmean[k],velocity[k])
TypeError: float argument required, not numpy.ndarray```

What I have tried:

I've tried to change the data types but I just cant get it to run
Posted
Richard MacCutchan 12-May-16 12:24pm

The final message tells you what to look for. One of those parameters is (assumed to be) a `numpy.ndarray`.