473,466 Members | 1,312 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

New to python, help with my program?

1 New Member
This program is supposed to read in a list of numbers and compute the average and standard deviation.

As it is now, it returns nothing. Any help would be greatly appreciated.

Expand|Select|Wrap|Line Numbers
  1. scores=raw_input('Type in scores on one line with a space between each one: ')
  2.  
  3. values = scores.split()
  4. for i in range (len(values)):
  5.     values[i] = int(values[i])
  6.  
  7. def average(values):
  8.     average=sum(values)/float(len(values))
  9.     return average
  10.  
  11. def standardDev(average, values):
  12.     total = 0
  13.     for i in values:
  14.         total +=(average-i)**2
  15.     standardDev= total/((len(values)-1)**.5)
  16.     return standardDev
Feb 20 '10 #1
1 1164
Motoma
3,237 Recognized Expert Specialist
If you take a look at your code, you will see that you have defined two functions, average and standardDev, but you never actually called them!

The code below shows you what you were missing:
Expand|Select|Wrap|Line Numbers
  1. def average(values):
  2.     average=sum(values)/float(len(values))
  3.     return average
  4.  
  5. def standardDev(average, values):
  6.     total = 0
  7.     for i in values:
  8.         total +=(average-i)**2
  9.     standardDev= total/((len(values)-1)**.5)
  10.     return standardDev
  11.  
  12. scores=raw_input('Type in scores on one line with a space between each one: ')
  13.  
  14. values = scores.split()
  15. for i in range (len(values)):
  16.     values[i] = int(values[i])
  17.  
  18. av =  average(values)
  19. sd = standardDev(av, values)
  20. print(sd)
  21.  
Now, to get rid of that pesky math error...
Feb 21 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
114
by: Maurice LING | last post by:
This may be a dumb thing to ask, but besides the penalty for dynamic typing, is there any other real reasons that Python is slower than Java? maurice
68
by: Lad | last post by:
Is anyone capable of providing Python advantages over PHP if there are any? Cheers, L.
0
by: metaperl | last post by:
A Comparison of Python Class Objects and Init Files for Program Configuration ============================================================================= Terrence Brannon bauhaus@metaperl.com...
10
by: notejam | last post by:
I am trying to get started with a interactive version of Python for windows and need some help. I have played with the tutorial, and now want to write a program. In basic language, I could write...
4
by: Julian | last post by:
Hi, first of all, I have to say I am new to Python. I have been working with a finite element analysis program written in c++. now, I am trying to 'rebuild' this code (possibly a full re-write)...
12
by: adamurbas | last post by:
ya so im pretty much a newb to this whole python thing... its pretty cool but i just started today and im already having trouble. i started to use a tutorial that i found somewhere and i followed...
34
by: Anthony Irwin | last post by:
Hi All, I am currently trying to decide between using python or java and have a few quick questions about python that you may be able to help with. #1 Does python have something like javas...
8
by: karthikbalaguru | last post by:
Hi, One of my python program needs tkinter to be installed to run successfully. I am using Redhat 9.0 and hence tried installing by copying the tkinter-2.2.2-36.i386.rpm alone from the CD 3 to...
1
by: =?ISO-8859-1?Q?Andr=E9?= | last post by:
Hi everyone, I'd be interested in hearing suggestions as to the "best" way to drive a Python program step by step from another application. Details: --------- I have implemented a "Robot"...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.