Wanted: Anyone moderately good with Jython

Recommended Videos

Chopp

New member
Aug 1, 2008
16
0
0
I'm extraodrinarily new at programming. I just started my first year of university, and I've hit a snag. And by snag I mean a "WHY WON'T THIS PIECE OF s*** WORK."

Here's the deal;

I have to write a program called "avg4", which takes 4 numbers and finds the average of them. That's no problem, what I have looks something like this;

def avg4(h,i,j,k):
print (h+i+j+k)/4.0

Now the problem is, I now have to write another program called "avg16", which asks the user to input 16 number and finds the average of them, but I have to use the above program to do so. What I have looks like this;

1 def avg4(h,i,j,k):
2 print (h+i+j+k)/4.0
3
4 def avg16():
5 w=avg4(input(),input(),input(),input())
6 x=avg4(input(),input(),input(),input())
7 y=avg4(input(),input(),input(),input())
8 z=avg4(input(),input(),input(),input())
9 print avg4(w,x,y,z)

But it doesn't work, and I can't for the life of me figure out why. Here's what happens;

>>> avg16()
1.0
1.0
1.0
1.0
The error was: 'NoneType' and 'NoneType'
Inappropriate argument type.
An attempt was made to call a function with a parameter of an invalid type. This means that you did something such as trying to pass a string to a method that is expecting an integer.
Please check line 2 of blahdyblahblah...

HALP.
 

Chopp

New member
Aug 1, 2008
16
0
0
I'm no Jython expert, but I suspect it's treating all input as string, and won't automatically cast it to integer.

edit: a quick search gets me this in regards to casting in Jython: "You must cast a variable to an integer before you can use it as an integer. You cast a variable as an integer by encapsulating the variable name by the keyword int()"