This Python script defines a function named factorial that takes a number as an argument and calculates its factorial using recursion. The script then calls the function with a user-provided number and prints the output.
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n-1)
number = int(input("Enter a Number: "))
print(f"Factorial of {number} is {factorial(number)}")Enter a Number: 5
Factorial of 5 is 120
This Python script asks the user for a number as input and uses the math module to calculate the square root, natural logarithm (log base e), and sine (in radians) of the number. The calculated results are then displayed.
import math
number = float(input("Enter a number: "))
sqrt_num = math.sqrt(number)
log_num = math.log(number)
sine_num = math.sin(number)
print(f"Square root of {number} is {sqrt_num}")
print(f"Natural logarithm (log base e) of {number} is {log_num}")
print(f"Sine of {number} (in radians) is {sine_num}")Enter a number: 25
Square root of 25 is 5.0
Natural logarithm (log base e) of 25 is 3.2188758248682006
Sine of 25 (in radians) is -0.13235175009777303
- Create a GitHub repository and upload your Python scripts (.py files).
- Ensure the repository includes a README.md file that describes the functionality of your programs.
- Add both Task 1 and Task 2 scripts in the same repository.
- Submit the link to your GitHub repository once uploaded.