DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Worksheet 1
Student Name:Aryan kumar UID:24BCS11115
Branch:CSE Section/Group:615-B
Semester:3 Date of Performance:
Subject Name:Programming in python Subject Code:24CSP-203
1. Aim:To print the factorial of a given number.
2. Requirements (Hardware/Software):hackerrank
3. Procedure: This program finds the factorial of a number. First, it takes
a number n from the user and sets a variable f to 1. Then it starts a loop
from n down to 1, and in each step, it multiplies the current value of f
with the loop number. In this way, it keeps multiplying all numbers from
n to 1. Finally, when the loop finishes, the program prints the value of f,
which is the factorial of the given number. For example, if you enter 5, it
calculates 5 × 4 × 3 × 2 × 1 = 120 and prints 120.
4. Code:
n=int(input())
f=1
for i in range(n,0,-1):
f=f*i
print(f)
5. Output:
6. Learning Outcome:
The learning outcome of this code is that you understand how
to calculate the factorial of a number using loops in Python.
From this program, you learn how to:
• Take user input and store it in a variable.
• Initialize variables before using them in calculations.
• Use a for loop with a range that decreases (counting
backwards).
• Perform repeated multiplication to build a result step by step.
• Understand the concept of factorial as the product of all
numbers from n down to 1.