bsc

Comprehensive codebase and coursework for the 4-year B.Sc. Computer Science Honours degree (WBSU)

git clone https://github.com/notamitgamer/bsc.git
· rebuilt hourlyOpen on GitHub
root / semester_2 / python / sec_5.py

sec_5.py (338B)


      1 # Function to calculate factorial
      2 def factorial(n):
      3     fact = 1
      4     for i in range(1, n + 1):
      5         fact = fact * i
      6     return fact
      7 
      8 # Main program
      9 num = int(input("Enter a number: "))
     10 if num < 0:
     11     print("Factorial is not defined for negative numbers.")
     12 else:
     13     result = factorial(num)
     14     print(f"Factorial of {num} is {result}")