Thread: Please help me

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    1
    Rep Power
    0

    Please help me


    Hello,

    We received a work assignment in Python but I missed too long since I graduate cum so I do not make this simple program and I need help with this task please can help me someone?

    Thank you in advance, this is a sign for me critical importing :-/

    I enclose entry:


    Code:
    Create a Python 3 line application called "spocti.py3" that processes the first command line argument with the text:  
    V (k, n) In (k, n) C (k, n) Co (k, n) P (n)  
    where n, to represent a particular number, 
    V = variation, 
    Vo = Variations with repetition
    C = combination, 
    Co = combination with repetition, 
    P = permutation.  
    
    Eg.:  $ ./spocti.py3 C (2,4)  calculates the combination of the second class of the 
    
    four elements and the output will  6  For the calculations, create separate functions. Remember to treat exceptions
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,837
    Rep Power
    480
    Code:
    #! /usr/bin/python3
    
    '''
        $ # example
        $ ./spocti.py3 C '(2,4)'
        6
    
        Save this code as file spocti.py3
        and make it executable:
        $ chmod +x spocti.py3
    '''
    
    import re
    import sys
    import math
    
    def use():
        print('use: {} f arg, with f arg in\n'.format(sys.argv[0])+
              'C (m,n)\n'
              'P (n)\n',
              file=sys.stderr)
        sys.exit(1)
    
    def combinations(arg):
        dense_arg = arg.replace(' ','')
        if not re.match('[(][0-9]+,[0-9]+[)]', dense_arg):
            use()
        a = dense_arg.replace('(','')
        b = a.replace(')','')
        (m, n,) = map(int, b.split(','))
        assert m <= n
        return math.factorial(n)//(math.factorial(m)*math.factorial(n-m))
    
    def main(function = None, *arguments):
        if 1 != len(arguments):
            use()
        if function == 'C':
            print(combinations(*arguments))
        else:
            print('function {} unimplemented.'.format(function))
    
    if '__main__' == __name__:
        main(*sys.argv[1:])
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo