A forum for general discussion of the Python programming language.


Postby Bioconstrictor » Fri Mar 15, 2013 9:12 pm

Im working with commandline options and could use some help (simplicity of language would be appreciated)

how do i Read the third command-line option as an integer.
and if the number is less than or equal to zero, print "too small".
-otherwise, create a list containing all the integers starting with 0
up to and including the number the user input.
- then print that list to standard out.
-If the sum of the numbers in the list is more than 10, print the
sum to standard out. Otherwise, print "sum is less than 10".
Posts: 1
Joined: Fri Mar 15, 2013 9:10 pm

Re: Commandline

Postby setrofim » Fri Mar 15, 2013 9:41 pm

  • To parse command line arguments: argparse
  • To convert an argument string to an integer, use the int() built-in.
  • For a list from 0 to X use xrange or range (if you're on Python 3.x)
  • To get the sum of numbers use the built-in sum() function.
If you want more help, post your attempt first.
Posts: 288
Joined: Mon Mar 04, 2013 7:52 pm

Return to General Discussions

Who is online

Users browsing this forum: No registered users and 4 guests