cruzheidy7486 cruzheidy7486
  • 07-11-2017
  • Computers and Technology
contestada

Write code to complete print_factorial()'s recursive case. sample output if user_val is 5: 5! = 5 * 4 * 3 * 2 * 1 = 120

Respuesta :

rsmith6559
rsmith6559 rsmith6559
  • 07-11-2017
```
#!/usr/local/bin/python3


import sys

def print_factorial( user_val ):
    if( user_val < 1 ):
        return( 1 )
    else:
        return( print_factorial( user_val - 1 ) * user_val )


if( __name__ == "__main__" ):
    if( len( sys.argv ) == 2 ):
        print( print_factorial( int ( sys.argv[ 1 ] ) ) )
    else:
        sys.stderr.write( "usage: %s <integer>\n" % sys.argv[ 0 ] )

    exit( 0 )
```

Answer Link

Otras preguntas

As energy in the form of heat is added to an ice cube, it begins to melt. What causes melting? A. Heat causes the molecules in the ice cube to expand and forces
How did the Grand Canal unite the country of China? It joined northern and southern China It made it possible to transport large amounts of grain grown in the s
What happens when organic molecules decompose?
(6-d)(d^2-5+3D) please help me answer this hahaha
a substance with fiber in it is often a
What is the relationship between changes in air pressure and wind
PLZ help use the terms alliance and speculator in a short paragraph to explain their meaning.
Which of the following men did NOT claim American land for Spain? Ponce de Leon Drake De Soto Coronado
if a judge makes a ruling on constitutional law based on a mix og her own personal views and court precedents then what is she employing A. sovereign immunity
What did the New Nationalism program support?