# ------------------------------------------------------------ #Student: Austin Wells #Class: CIS122 #Date: 4/24/2015 #Program Title: Chapter 5 Programming Excercise 12.py #(Calculating the factorial of a Number) #Program Description: Prompts the user for a non negative integer and returns the factorial of that number # ------------------------------------------------------------ # total rainfall input function def calculateFactorial(userInput): factorial = userInput for i in range(1,userInput): factorial = factorial * i return factorial # prompts user for input. def promptForNumber(strPrompt): userInput = int(raw_input(strPrompt + ": ")) print '{}' .format(userInput) return userInput #main driver function def main(): try: userInput = promptForNumber("Please enter a non negative integer ") factorial = calculateFactorial(userInput) print '{}! is {:0,}' .format(userInput,factorial) except (ValueError): print '\n\nInvalid input. You have entered a non integer. Please enter an integer' except (EOFError): print '\n\nInvalid input. You have forgotten to add input. Please Reset program and Please enter an integer' main()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question