You are on page 1of 3

Additional programs for practice

1. Write a program to print n natural number in descending order using a while


loop.

# N natural number
n = int(input("Enter range: ")) #10
while(n!=0):
print(n, end=" ")
n = n - 1

2. Write a program to display the first 7 multiples of 7.

# First 7 numbers multiple of 7


count = 0
for i in range(200):
if i%7 == 0:
print(i,end=" ")
count = count+1
if count == 8:
break

3. Write a program in Python to display the Factorial of a number.

# Factorial of a number
n = int(input("Enter number: ")) # 5
if(n == 0 or n < 0):
print("Value of n should be greater than 1")
else:
fact = 1
while(n):
fact *= n
n = n-1
print(f"Factorial is {fact} ")

4. Write a program in Python to reverse a word.

str = input("Input a word to reverse: ")

for i in range(len(str) - 1, -1, -1):


print(str[i], end="")
print("\n")

5. Write a Python program to construct the following pattern, using a nested


for loop.
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
Solution:
n=5;
for i in range(n):
for j in range(i):
print ('* ', end="")
print('')

for i in range(n,0,-1):
for j in range(i):
print('* ', end="")
print('')
Find out the answers for the below programs
6. Program to Count the Number of Vowels in a string and print the vowels
7. To print a string in reverse order.
8. To find a number from a list of 10 numbers.
9.

You might also like