[Tutor] Running python from windows command prompt

Alan Gauld alan.gauld at btinternet.com
Thu Apr 11 08:29:32 CEST 2013


On 11/04/13 07:08, Arijit Ukil wrote:
> Thanks for the help. Now I have modifed the code as:
>
> import sys
>
> def main(argv):
>      data = int(sys.argv[1])
>      avg = average (data)
>      print "Average:", avg
>
> def average(num_list):
>      return sum(num_list)/len(num_list)
>
> if __name__ == "__main__":
>     main(sys.argv[1:])
>
> When running in command line I am getting these errors:
> In case 1. data = sys.argv[1]
> In case 2, data = float(sys.argv[1])
> In case 3, data = int (sys.argv[1])

Try printing data to see what you are doing wrong in each case.
You need data to be a list of numbers. None of your three cases produces 
that.



-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list