Monday, May 25, 2020
Home PYTHON looping and iteration statements

# looping and iteration statements

### Python program for printing Half Pyramid pattern using numbers

n = int(input("Please enter the number of rows: ")) for num in range(1, n + 1): for i in range(num): print...

### Python program for printing Half Pyramid pattern using asterisk symbol

num_rows = int(input("Please enter the number of rows: ")) m = (2 * num_rows) - 2 for i in range(0, num_rows): for j in range(0,...

### Python program to check number is prime or not

num=int(input("Please enter any number: ")) lim=int(num/2)+1 for i in range(2,lim): rem=num%i if rem==0: ...

### Python program to print table of any given number

num=int(input("Please enter any number: ")) for a in range(1,11): print(num,'x',a,'=',num*a) Output: Please enter any...

### Python program to calculate the factorial of a number using while loop

num=int(input("Enter a number: ")) fact=1 a=1 while(a<=num): fact=fact*a #fact*=a a=a+1 ...

### Python program to print all even numbers from m to n using for loop

lower_limit = int(input("Enter the start of range: ")) upper_limit = int(input("Enter the end of range: ")) for num in range(lower_limit, upper_limit + 1): #...

### Python program to print all odd numbers from m to n using for loop

lower_limit = int(input("Enter the start of range: ")) upper_limit = int(input("Enter the end of range: ")) for num in range(lower_limit, upper_limit + 1): #...

### Python program to print all numbers from m to n using for loop

min_value = int(input("Please Enter the Minimum Value : ")) max_value = int(input("Please Enter the Maximum Value : ")) print("Numbers from {0} to {1} are".format(min_value, max_value)) for i...

### Python program to print natural numbers from 1 to n numbers using while loop

num = int(input("Please Enter any Number: ")) i = 1 print("Natural Numbers from 1 to {0} are".format(num)) while (i <= num): print (i, end = ' ') ...

#### Stay connected

19,697Fans
2,180Followers
14,700Subscribers

### Python program to display the fibonacci sequence using recursive

def recursive_fibo(num): if num <= 1: return num else: ...

### Python program to find the product of two numbers using recursive

def mult_product(x,y): if(x<y): return mult_product(y,x) elif(y!=0): ...

### Python program to convert octal to decimal using function

def octal_to_dec(n): # Function which is convert octal to decimal num = n; dec_value = 0; ...