Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1- Using python write a program that calculates n! (n-factorial). The program sh

ID: 2082308 • Letter: 1

Question

1- Using python write a program that calculates n! (n-factorial). The program should at the beginning of the
calculation print “Now calculating n!”, with “n” being whatever real integer is being used in
that instance of the program. It should then print what n! calculates to.
2 Write a program that uses loops to generate pyramid-like shapes as shown below, using
dashes:
-
--
--- ---- ----- ---- ---
--
-
-
--
--- ---- ----- ------ ----- ---- ---
--
-
The program MUST use at least two loops. Do not just have 18 “print” statements, that will be marked as a zero.

plz don't copy answers

Explanation / Answer

1.

n = 5

# initializedn with a number

factorial = 1

print("calculating n!")

if n < 0:

print("factorial never exist for negative numbers")

elif n == 0:

print("The factorial of 0 is 1")

else:

for i in range(1,n + 1):

factorial = factorial*i

print("The factorial of",n,"is",factorial)

Output:

Calculating 5!

Factorial of 5 is 120