0% found this document useful (0 votes)
3 views1 page

Prime Check, Factorial, Fibonacci & Patterns

The document contains several Python programs demonstrating basic programming concepts. It includes programs to calculate the factorial of a number, check if a number is prime, reverse a number, and display the Fibonacci series. Additionally, it features a simple pyramid pattern output example.

Uploaded by

rudranshsahu5162
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Prime Check, Factorial, Fibonacci & Patterns

The document contains several Python programs demonstrating basic programming concepts. It includes programs to calculate the factorial of a number, check if a number is prime, reverse a number, and display the Fibonacci series. Additionally, it features a simple pyramid pattern output example.

Uploaded by

rudranshsahu5162
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

# Program to find

factorial of a number #Program to check if a


using while loop number is prime or not
num = int(input("Enter a num = int(input("Enter a
number: ")) number: "))
factorial = 1 if num <= 1:
i=1 print("Not a prime
number.")
if num < 0: else:
print("Factorial does is_prime = True
not exist for negative i=2
numbers.") while i <= num // 2:
elif num == 0: if num % i == 0:
print("The factorial of is_prime = False
0 is 1.") break
else: i += 1
while i <= num:
factorial *= i if is_prime:
# Program
i += 1to reverse a number using while loop print(num,"is a
print("The factorial prime number.")
num = int(input("Enter a number: "))
of",num,"is",factorial) else:
reverse = 0
print(num,"is not a
while num > 0:
prime number.")
digit = num % 10 # get the last digit
reverse = (reverse * 10) + digit # add it to reverse
num //= 10 # remove the last digit

print("The reverse of the number is:", reverse) '''Pyramid pattern


Output:

*
**
***
# Program to display Fibonacci series using while loop (0 1 1 2 3 5 8 13 21.......) ****
* * * * * '''
n = int(input("Enter the number of terms: ")) rows = 5
a, b = 0, 1
for i in range(1, rows + 1):
count = 0
print(" " * (rows - i) + "* " * i)
if n <= 0:
print("Please enter a positive integer.")
else:
print("Fibonacci sequence:")
while count < n:
print(a, end=" ")
next_term = a + b
a=b
b = next_term
count += 1

You might also like