give me an example of a python script
Jump to turn (16)
- 1give me an example of a python script
- 2give me an example of python script being used in excel
- 3give me an example of a real world python script
- 4give me an example of a complex python script
- 5give me an example of a real world sql example
- 6will maidsafe coin be successful
- 7what was the original price of ethereum
- 8what exchanges was ethereum available on in 2015
- 9when was ethereum available on coinbase
- 10what price was ethereum when it launched on coinbase
- 11show python script for excel which has a range which is a list
- 12what is the typical purpose for using python
- 13is python typically used with excel
- 14is it better to use python scripts for automation than vba
- 15is vba obsolete
- 16is it still valuable to learn vba
- User
give me an example of a python script
- Assistant
Sure! Here's an example of a simple Python script that calculates the factorial of a given number:
pythondef factorial(n): if n == 0: return 1 else: return n * factorial(n-1) num = int(input("Enter a number: ")) if num < 0: print("Factorial does not exist for negative numbers.") elif num == 0: print("Factorial of 0 is 1.") else: print("Factorial of", num, "is", factorial(num))In this script, the
factorialfunction is defined recursively to calculate the factorial of a given number. The user is prompted to enter a number, and the script then calculates and displays its factorial. It also handles negative numbers and displays appropriate messages accordingly.