Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

 Loop Concept in Python:-

It is used to print range based data using a common repeatable block. It is also called iterative statement because it is used to enumerate data of LIST, Tuple, Dictionary, Set, and Database objects.

for example, if we want to print data from 1 to 1000 then we will prefer a loop statement.

1) While Loop Example in Python:-




 2) For Loop in Python:-


3) Nested For Loop in Python with Example:-



Flow of Loop

1    Forward     i=min      i<=max      i=i+1                  range(min,max)

2    Backward   i=max     i>=min      i=i-1                  range(max,min,-1)
      
3    Infinite       i=min,max  ,no condition, i=i+1,i=i-1


Type of Loop:-

1)  while loop and while--else loop:-

it will provide all statements of loop separately and it is mainly used to create an infinite condition-based program.

init;   

while(condition):
     Statement
     Increment


The direction of Loop Statements:-


Forward                        Backward

i = min                          i=max

i<= max                        i>=min

i = i+1                          i=i-1



Q) WAP to print 1 to 10?

i=1
while(i<=10):
   print(i)
   i=i+1


Q) WAP to print 10 to 1?

i=10
while i>=1:
    print(i)
    i=i-1



  


Q) WAP to print a table of any entered number?

num=int(input("enter number to caculate table"))
i=1
while(i<=10):
    print(str(num) + "*"+ str(i) + "=" + str(num*i))
    i=i+1




Q) WAP to print 1 to 5 and  5 to 1 using a single while loop?

1
2
3
4
5
5
4
3
2
1

Solution:- 

i=1
while(i<=10):
    if i<=5:
      print(i)
    else:
      print(11-i) 
    i=i+1

WAP to calculate square and cube of one digit positive number?

1      1       1
2      4       8
3      9      27
...

Solution:-

start = int(input("enter starting point"))
end = int(input("enter ending point"))

i=start
while(i<end):
    s=i*i
    c=i*i*i
    print(i,s,c)
    i=i+1


Assignment of While Loop 

Q)WAP to calculate square and cube of one digit positive number?


Q)WAP to print 1 to 5 and  5 to 1 again 1 to 5 and 5 to 1 using a single while loop?


Q)WAP to perform the addition of a one-digit positive number?  
 


1 to 9 = 55

sum=0

i=1

s= ''

while i<10:

    sum=sum+i

    if i<9:

     s = s + str(i) + "+"

    else:

     s = s + str(i) + "="   

    i=i+1


print(s,sum)

Q)WAP to calculate factorial of a number with complete expression? 

hint:-  factorial of five

5*4*3*2*1=120


The solution to this program:-

num = int(input("Enter number to calculate factorial"))
i=num
f=1
while i>=1:  # 0>=1  False
   f = f*i   # f = 120*1 120
   i= i-1    # i =0

print("factorial is ",f)    


Q) WAP to check prime number?

The solution to this program:-


Solution First to check the divisibility of number from 1 to number?

num = int(input("enter number to check prime"))
count=0
i=1
while i<=num:
    if num%i==0:
        count=count+1
    i=i+1

if count==2:
    print("prime")
else:
    print("not prime")



Solution 2:-  

num = int(input("enter number to check prime"))
i=2
count=0
while i<num:
    if num%i==0:
        count=1
        break
    i=i+1

if count==0:
    print("prime")
else:
    print("not prime")
    

Q)WAP to reverse any digit number?

hint, for example, user enter 54326   then the output will be 62345

Q) WAP to find max digit, second max digit in mobile number?

hint:-  for example users enter 12345 then the output will be maxed 5 and the second max will be 4.

a= 681236783
8
7
The solution to this program:-

num = int(input("enter mobile number"))
m=0
sm=0


while(num!=0):
    rev = num%10
    print(rev)
    num = num//10
    if m<rev:
        sm=m
        m=rev
    elif sm<rev and sm!=m:
        sm=rev

print(m,"",sm)  

 


Example of While else:-

Else statement always used with if statement but in a python script, we can use else statement with a while and for loop both. Else block will be executed when the loop condition will false.

#while else example


WAP to reverse number?


num = int(input("enter number"))
s=''
while num!=0:
    s=s+str(num%10)
    num=num//10
else:
    print(s)


Q) WAP to check prime number using While--else statement in Python?

num = int(input("enter number to check prime"))
i=2
while i<num:
    if num%i==0:
        print("not prime")
        break
    i=i+1
else:
    print("prime")






WAP to calculate factorial of any number?

num = int(input("enter number to calculate factorial"))
f=1
i=num
s=''
while i>1:  # i=num;i>1;i--
    f=f*i  #f=5 20  60 120
    s=s+str(i)+"*"
    i=i-1

print("factorial is ",s+"1=",f)    


Infinite While Loop:-


If we provide a condition that is not determined initially then we use an infinite while loop.


Syntax:-

while True:
     Statement



while True:
    print("Ram")




2)   for loop and for..else:-

using this we will print all sub statements using a single range() method.
range() is used to provide starting and ending points to the process loop.

range(start, end)    it contains two parameters first starting point and another one is the ending point.


for i in range(min,max):     #forward  increment by default 1
       statements


for i in range(max,min,-1):  #backward direction
     statement


Special cases on For Loop:-

for i in range(1,11):  # i=1; i<11; i=i+1
    print(i)
    i=i+10
    print(i)


This program will display data 10 times and increase by 1 only.

Another program of for loop to understand better

for i in range(11,1,-1):  # i=1; i<11; i=i+1
    print(i)
    i=i+10
    print(i)

...........................................................................................................

Q) WAP to print 1 to 10?

for i in range(1,11):
   print(i)


WAP to print 10 to  1?

for i in range(10,0,-1):
    print(i)



WAP to print a table of odd numbers?

num=int(input("enter number"))
if num%2!=0:
   for i in range(1,11):
      k=num*i
      print(k)
else:
    print("enter only odd number")

WAP to display fibonacci series?

#fibonacci series 0 1 1 2 3 5 8 13 21


a=-1
b=1
for i in range(1,11):
    c=a+b           #0 1 1 2 3
    print(c)
    a=b              #1
    b=c              #1


WAP to calculate factorial of any number with complete expression?


num = int(input("enter number to calculate factorial"))
f=1
s=''
for i in range(num,1,-1):  # i=num;i>1;i--
    f=f*i  #f=5 20  60 120
    s=s+str(i)+"*"

print("factorial is ",s+"1=",f)    


For..else:-

It will be executed when for loop condition will false. if we use a break statement and terminate the loop then else the statement will not work.


for i in range(min,max):
     Statements
else:
     Statements

Example of for--else

WAP to calculate the sum of one digit positive number?

sum=0
for i in range(1,10):
    sum=sum+i
else:
    print("Total is ",sum)



Another example of For--Else using break?

Run this program and analyze the output of this.

for i in range(1,11):
    print(i)
    if i==7:
        break
else:
    print("Total execution of loop is "+str(i))






Nested For Loop:-

Using this we will write more than one for loop using a nested sequence, It is a collection of Outer for loop and inner for loop.

Outer for loop will execute once and the inner for loop will be executed until the condition will false. when the outer loop condition will false then the loop program will be terminated.


for i in range(start, end):  row   or outer for loop
   for j in range(start,end):  column  or inner for loop
           Statement
         
   NewLineStatement




Solve these problems using Nested For loop:-


1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
...............................................................................................

1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

Solution:-

for i in range(5,0,-1):
    for j in range(1,i+1):
        print(j,end=' ')
    print()    

........................................
  I  j
1   5
2   4
3   3
4   2
5   1

for i in range(1,6):
    for j in range(1,7-i):

A B C D E
A B C D
A B C
A B
A
.............................................................

A
A B
A B C
A B C D
A B C D E

.....................................
I j
1 1
2 2
3 3
4 4
5 5

for i in range(1,6):
    for j in range(1,7-i):




Assignment of Nested For Loop In Python:

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
............................................

A B C D E
a  b  c  d
A B C
a b
A


The solution to this pattern:-

for i in range(70,65,-1):
    for j in range(65,i):
        if i%2==0:
         print(chr(j),end=' ')
        else:
         print(chr(j+32),end=' ') 
    print() 

...........................................................

A  a B b C
A a B b
A a B
A a
A

The solution to this program:-
for i in range(70,65,-1):
    k=65
    for j in range(65,i):
        if j%2==0:
         print(chr(k+32),end=' ')
         k=k+1
        else:
         print(chr(k),end=' ')
       
    print() 



.........................................................

1 2 3 4 5
5 4 3 2
1 2 3
5 4
1

The solution to this pattern:-

for i in range(1,6):
    for j in range(1,7-i):
        if i%2==0:
         print(6-j,end=' ')
        else:
         print(j,end=' ') 
    print()
 

......................................................................
1 0 0 1 0
1 0 0 1
1 0 0
1 0
1
...............................................................................

The solution of This program:-


for i in range(1,6):
    a=1
    b=0
    for j in range(1,7-i):
        if j%2==0:
         print(b,end=' ')
         b=1
        else:
         print(a,end=' ')
         a=0
    print()
 


Create a Pattern to print this pattern:-

A B C D E
    B C D E
        C D E
           D E
               E


The solution to this program:-

for i in range(0,5):
    ch=65
    for k in range(0,i):
        print(' ',end=' ')
        ch=ch+1
    for j in range(i,5):
        print(chr(ch),end=' ')
        ch=ch+1
        
    print()    


...........................................

                *
        *      *       *
*     *       *       *     *
       *       *      *
                *



Solution of this program:-

start=3
l=2 
for i in range(1,6):
    if i<=3:   
     for k in range(start,i,-1):
        print(" ",end='')
     
     for j in range(0,2*i-1):
        print("*", end='')
    else:
        
     for k in range(start,i):
        print(" ",end='')
     
     for j in range(0,2*(l)-1):
        print("*", end='')
     l=l-1   
         
    print()    
        
    

 
..............................

Infinite Loop in Python:-

This loop will continuously be executed until the condition false.we always prefer while loop for infinite condition and for loop for the finite condition.

Syntax of While Loop:-

while(true):
    Statement

Example of Simple While Loop for the infinite condition?

while True:
     print("*")

This program print infinite * symbols on the output screen

How we can convert the Infinite loop to stop mode?

We can ask user's input or last limit and convert true condition to false condition.

Example of this 

flag=True
i=1
while flag:
    print("*")
    i=i+1
    if i>10:
       flag=False 
        


in this program we convert the infinite loop to finite when I value will be 10 then the loop will be automatically terminated.


Minor project work on Loop Statements?


ATM:-

WAP to manage ATM operation with the following instruction

1)  When an application will be loaded then ask for the pin code, if the pin code is correct then the process to the next phase otherwise asks pin code three times if it will be wrong then the application will be closed automatically.


 2)   If the pin code is correct then ask for operation using the menu  Press C for Credit, D for Debit, B for check balance, E for the exit, R for a Repeat operation.

3)   If the user performs three operations then automatically exit from the application.

4)  Display all log means the internal process

95 Comments

If you have any doubt in programming or join online classes then you can contact us by comment .

  1. #print 10 to 1
    print(" Decrease value 10 -1 ")
    i=10
    while (i>=1):
    print(i)
    i=i-1
    print("\n*************")
    print ( "Increase value 1-10 ")
    #print 1 to 10
    i=1
    while (i<=10):
    print(i)
    i=i+1

    ReplyDelete
  2. #print 5 to 1 and 1 to 5 programm
    print(" Decrease value 10 -1 ")
    i=5
    while (i>=1):
    print(i)
    i=i-1
    print("\n*************")
    print ( "Increase value 1-10 ")
    #print 1 to 5
    i=1
    while (i<=5):
    print(i)
    i=i+1

    ReplyDelete
  3. #perform the addition of a digit positive number? 1 to 10 = 55
    i=1
    sum=0
    while (i<=10):
    sum = sum + i
    print(i)
    i=i+1
    print("------------------------")
    print ("The Sum is " ,sum)

    ReplyDelete
  4. for i in range(5,0,-1):
    for j in range(1,i+1):
    print(i,end=' ')
    print()

    ######
    Output :
    5 5 5 5 5
    4 4 4 4
    3 3 3
    2 2
    1

    ReplyDelete
  5. Write a program to calculate factorial number

    n = int(input("Enter the number:"))
    result = 1

    for i in range(n,0,-1):
    result = result*i
    print("factorial of",n,"is",result)

    ReplyDelete
  6. ATM Program Solution

    flag=False
    p=1721
    bal=500
    for i in range(1,4):
    pin = int(input("enter pin code"))
    if pin==p:
    flag=True
    break
    while(flag):



    if flag:
    ch = input(" Press C for credit \n Press D for bedit \n Press b for check balance \n press e for exit")
    if ch=='c':
    amt = int(input("enter amount"))
    bal+=amt
    elif ch=='d':
    amt = int(input("enter amount"))
    bal-=amt
    elif ch=='b':
    print("Your current balance is ",bal)
    else:
    break


    else:
    print("Incorrect pin code and your all attempt has completed")






    ReplyDelete
  7. wap to print 1to10 using while lopp
    i=1
    while(i<=10)
    ptint(i)
    i=1+1

    ReplyDelete
  8. wap to 10 to 1 using while loop
    i=10
    while(i>=1):
    print(i)
    i=1-1

    ReplyDelete
  9. #wap to calculate table using while loop
    a=int(input("enter number"))
    i=1
    while(i<=10)
    b=a*1
    print(b)
    i=i+1

    ReplyDelete
  10. wap to print 1to5 and 5to1 in single loop
    i=1
    while(i<=10):
    if(i<=5):
    print(i)
    else:
    print(11-i)
    i=i+1

    ReplyDelete
  11. wap to print (111 2 4 8 3 9 27)
    num=1
    i=1
    while(i<=9)
    if(num<=9)
    print(str(num)+""+str(num*i)+""+str(num*i*i))
    num=num+1
    i=i+1

    ReplyDelete
  12. #square and cube of one digit positive number
    num=1
    i=1
    while(i<=9):
    if(num<=9):
    print(str(num*num))
    num=num+1
    i=i+1
    #calculate cube
    #wap to calculate square and cube of a number
    num=1
    i=1
    while(i<=9):
    if(num<=9):
    print(str(num*num*num))
    num=num+1
    i=i+1

    ReplyDelete
  13. #check prime number
    num=int(input("check prime number"))
    c=0
    i=1
    while(i<=num):
    if num%i==0:
    c=c+1
    i=i+1

    if c==2:
    print("prime no")
    else:
    print("not prime")

    ReplyDelete
  14. Program for table of a number>>>>

    num=int(input("enter number to caculate table"))
    i=1
    while(i<=10):
    print(str(num) + "*"+ str(i) + "=" + str(num*i))
    i=i+1
    Ex--->>
    101*1=10
    101*2=202
    '
    '
    '
    '
    '
    101*9=909
    101*10=1010

    ReplyDelete
  15. #wap reverse a number using whileelse
    num=int(input("enter number that you want to reverse"))
    s=""
    while(num!=0):
    s=s+str(num%10)
    num=num//10
    else:

    print(s)

    ReplyDelete
    Replies
    1. deependra singh jadaunNovember 8, 2020 at 6:45 PM

      program run nahi ho rha h

      Delete
  16. Program to check whether number is prime or not--->>>

    num = int(input("enter number"))
    total=0
    i=1
    while i<=num:
    if num%i==0:
    total=total+1
    i=i+1

    if total==2: #Prime number is which is divisible by 1 and itself both,so this
    condition is used
    print("It is a prime number")
    else:
    print("It is not a prime number")

    ReplyDelete
  17. Program to print 1 to 4 and 4 to 1 using a single while loop--->>

    i=1
    while(i<=8):
    if i<=4:
    print(i)
    else:
    print(9-i)
    i=i+1

    ReplyDelete
  18. #wap to print 12345
    #12345
    #12345
    #12345
    #12345
    for i in range(1, 6):
    temp = ''
    for j in range(1, 5):
    temp += str(j)
    print(temp)

    ReplyDelete
  19. 1 2 3 4 5
    1 2 3 4
    1 2 3
    1 2
    1
    for i in range(5,0,-1):
    for j in range(1,i+1):
    print(j,end='')
    print()

    ReplyDelete
  20. A B C D E
    A B C D
    A B C
    A B
    A
    for i in range(70,65,-1):
    for j in range(65,i):
    j=chr(j)
    print(j,end=' ')
    print()

    ReplyDelete
  21. #wap to print
    """A
    A B
    A B C
    A B C D
    A B C D E"""
    for i in range(1,6):
    for j in range(65,65+i):
    print(chr(j), end= '')
    print()

    ReplyDelete
  22. Assignment of Nested For Loop In Python:

    1
    1 2
    1 2 3
    1 2 3 4
    1 2 3 4 5


    for i in range(1,6):
    for j in range(1, i+1):
    print(j, end="")
    print()

    ReplyDelete
  23. """A B C D E
    a b c d
    A B C
    a b
    A"""
    for i in range(70,65,-1):
    for j in range(65,i):
    if i%2==0:
    print(chr(j),end="")
    else:
    print(chr(j+32),end="")
    print()

    ReplyDelete
  24. Program to calculate Square and cube of a number---->>


    strt=int(input("enter starting point"))
    end=int(input("enter ending point"))
    i=strt
    while(i<end):
    s=i*i
    e=i*i*i
    print(s,e.i)
    i=i+1

    Ex.---enter starting point4
    enter ending point9
    4 16 64
    5 25 125
    6 36 216
    7 49 343
    8 64 512

    ReplyDelete
  25. Program to print 12345678910--->>

    for i in range(1, 3):
    tp = ""
    for j in range(1, 11):
    tp += str(j)
    print(tp)

    ReplyDelete
  26. Program to print sum of numbers---->>>

    sum=0
    i=1
    p=""
    while i<15:
    sum=sum+i
    if i<14:
    p= p+str(i)+ "+"
    else:
    p= p+str(i)+ "="
    i=i+1
    print(p,sum)

    ReplyDelete
  27. Program to print reverse of a number---->>

    num=int(input("enter number"))
    s=""
    while(num!=0):
    s=s+str(num%10)
    num=num//10
    else:
    print("reverse is",s)

    ReplyDelete
  28. Program to print reverse of a number using while loop---->>

    num=int(input("enter number"))
    s=""
    while(num!=0):
    s=s+str(num%10)
    num=num//10
    print("rev is",s)

    ReplyDelete
  29. Program to calculate factorial of a number----->>

    num=int(input("Enter the number"))
    r=1

    for i in range(num,0,-1):
    r=r*i
    print("factorial of entered number is",r)

    ReplyDelete
  30. Program for factorial-->


    num = int(input("enter the number"))
    f=1
    i=num

    while i>1:
    f=f*i

    i=i-1

    print("factorial is ",f)

    ReplyDelete
  31. """1 2 3 4 5
    1 2 3 4 5
    1 2 3 4 5
    1 2 3 4 5
    1 2 3 4 5"""
    for i in range(1,6):
    for j in range(1,6):
    print(j,end='')
    print()

    ReplyDelete
  32. """A B C D E
    A B C D
    A B C
    A B
    A"""
    for i in range(70,65,-1):
    for j in range(65,i):
    print(chr(j),end="")
    print()

    ReplyDelete
  33. """A
    A B
    A B C
    A B C D
    A B C D E"""
    for i in range(65,70):
    for j in range(65,i+1):
    print(chr(j),end='')
    print()

    ReplyDelete
  34. """1
    1 2
    1 2 3
    1 2 3 4
    1 2 3 4 5"""
    for i in range(1,6):
    for j in range(1,i+1):
    print(j,end='')
    print()

    ReplyDelete
  35. """A B C D E
    a b c d
    A B C
    a b
    A
    """
    for i in range(70,65,-1):
    for j in range(65,i):
    if i%2==0:
    print(chr(j),end='')
    else:
    print(chr(j+32),end='')
    print()

    ReplyDelete
  36. Q :- wap to print 1 to 10 using while loop ?
    Solution:-
    i=1
    while(i<=10):
    print(i)
    i=i+1

    ReplyDelete
  37. Q:- wap to 10 to 1 using while loop ?
    Solution :-
    i=10
    while(i>=1):
    print(i)
    i=i-1

    ReplyDelete
  38. Q :- WAP to print a table of any entered number ?
    Solution :-
    n=int(input(" Enter number to Caculate table :- "))
    i=1
    while(i<=10):
    print(str(n) + " * "+ str(i) + " = " + str(n*i))
    i=i+1

    ReplyDelete
  39. Q:- wap to print 1 to 5 and 5 to 1 using a single while loop ?
    Solution:-
    i=1
    while(i<=10):
    if i<=5:
    print(i)
    else:
    print(11-i)
    i=i+1

    ReplyDelete
  40. wap to Calculate Square and Cube of one digit positive number ?
    Solution:-
    start = int(input("Enter starting point :- "))
    end = int(input("Enter ending point :- "))

    i=start
    while(i<end):
    s=i*i
    c=i*i*i
    print(i, " = Square is :- " ,s, " Cube is :- ",c)
    i=i+1

    ReplyDelete
  41. Q:- wap to calculate factorial of a number with complete expression ?
    Solution :-

    n = int(input("Enter number to calculate factorial :- "))
    i=n
    fact=1
    while i>=1:
    fact = fact*i
    i= i-1

    print("Factorial of " , n , " is ",fact)

    ReplyDelete
  42. Q:- wap to reverse number ?
    Solution:-
    n = int(input("Enter Number :- "))
    s=''
    while n!=0:
    s=s+str(n%10)
    n=n//10
    else:
    print(s)

    ReplyDelete
  43. Q:- wap to check prime number using While - else statement in Python ?
    Solution:-
    n=int(input("Enter number to check prime or not prime :- "))
    i=2
    while i<n:
    if n%i==0:
    print("This is not Prime Number.")
    break
    i=i+1
    else:
    print("This is Prime Number.")

    ReplyDelete
  44. Q:- wap to print 1 to 10 ?
    Solution:-

    for i in range(1,11):
    print(i)

    ReplyDelete
  45. Q:- wap to print 10 to 1 ?
    Solution:-
    for i in range(10,0,-1):
    print(i)

    ReplyDelete
  46. Q:- wap to print a table of odd numbers ?
    Solution:-
    n=int(input("Enter a Number :- "))
    if n%2!=0:
    for i in range(1,11):
    a=n*i
    print(a)
    else:
    print("Enter only Odd Number.")

    ReplyDelete
  47. Q:- wap to print a table of even numbers ?
    Solution:-
    n=int(input("Enter a Number :- "))
    if n%2==0:
    for i in range(1,11):
    a=n*i
    print(a)
    else:
    print("Enter only Even Number.")

    ReplyDelete
  48. deependra singh jadaunNovember 6, 2020 at 9:22 AM

    program to calculate square and cube of one digit positive no.
    i=1
    while i<10:
    print(i , i**2 , i**3)
    i=i+1

    ReplyDelete
  49. deependra singh jadaunNovember 6, 2020 at 9:36 AM

    WAP to print 1 to 5 and 5 to 1 again 1 to 5 and 5 to 1 using a single while loop?
    i=1
    while i<=20:
    if i<=5:
    print(i)
    else:
    if i<=10:
    print(str(11-i))
    else:
    if i<=15:
    print(i-10)
    else:
    print(21-i)
    i=i+1

    ReplyDelete
  50. deependra singh jadaunNovember 13, 2020 at 3:01 PM

    wap to calculate table of odd no.
    i=int(input("enter any no."))

    for n in range (1,11):
    if i%2==0:
    print("enter only odd no.")
    else:
    if i%2 !=0:

    print(str(i)+ "*" +str(n)+"="+str(n*i))

    ReplyDelete




  51. # PYTHON (6 To 7 PM BATCH)
    #Program to print 1 to 5 and 5 to 1 again 1 to 5 and 5 to 1 using while loop

    i=1
    w=0
    while(w<=20):
    if i<=5:
    print(i)
    elif i==6 or i<=10:
    print(11-i)

    elif i==11:
    i = 0

    i=i+1
    w=w+1

    ReplyDelete
  52. #PYTHON(6 To 7 BATCH)
    #CODE to perform the addition of a one-digit positive number
    i= 0
    a= 1
    s=0
    while(i<=10):
    if i<=9:
    print(a,"+",i,"=",a+i)
    else:
    print("\nTotal","=",s)
    s=s+a+i
    i=i+1

    ReplyDelete
  53. # PYTHON( 6 To 7 BATCH)
    # Program to factorial of a number with complete expression
    num = int(input("Enter the number for factorial:\t"))
    i=num
    f=1
    while i>=1:
    f = f*i
    print(i,end = 'X')
    i= i-1
    if i==1:
    print(i,"=",end ='')
    print("\t",f)
    break

    ReplyDelete
  54. #PYTHON(6 to 7 PM BATCH)
    #CODE to reverse any Number or Alphabet

    num = input("Enter Number or Alphabet:\t")
    print(num[::-1])

    ReplyDelete
  55. #WAP to calculate square and cube of one digit positive number?

    a = int(input("Enter number = "))
    i =1
    while ( i<=a):
    print(str(i) +" "+ str(i * i) +" "+ str(i * i * i))
    i = i+1

    ReplyDelete
  56. ABHISHEK GOYAL
    #WAP to print a table of any entered number?

    num=int(input("enter number to caculate table"))
    i=1
    while(i<=10):
    num=num*i
    i=i+1
    print(num)

    ReplyDelete
  57. ABHISHEK GOYAL
    #WAP to calculate square and cube of one digit positive number?

    a = int(input("enter starting point"))
    b = int(input("enter ending point"))

    i=a
    while(i<b):
    s=i*i
    c=i*i*i
    print(i,s,c)
    i=i+1

    ReplyDelete
  58. ABHISHEK GOYAL
    #WAP to perform the addition of a one-digit positive number?

    sum=0
    i=1
    s= ''
    while i<10:
    sum=sum+i
    if i<9:
    s = s + str(i) + "+"
    else:
    s = s + str(i) + "="
    i=i+1

    print(s,sum)

    ReplyDelete
  59. ABHISHEK GOYAL
    #WAP to calculate factorial of a number with complete expression?

    num = int(input("Enter number to calculate factorial"))
    i=num
    f=1
    while i>=1:
    f = f*i
    i= i-1

    print("factorial is ",f)

    ReplyDelete
  60. ABHISHEK GOYAL
    #WAP to check prime number?

    num = int(input("enter number to check prime"))
    i=2
    count=0
    while i<num:
    if num%i==0:
    count=1
    break
    i=i+1

    if count==0:
    print("prime")
    else:
    print("not prime")

    ReplyDelete
  61. ABHISHEK GOYAL
    #WAP to reverse number?


    num = int(input("enter number"))
    s=''
    while num!=0:
    s=s+str(num%10)
    num=num//10
    else:
    print(s)

    ReplyDelete
  62. 1 to 9 = 55
    sum=0
    i=1
    s= ''
    while i<10:
    sum=sum+i
    if i<9:
    s = s + str(i) + "+"
    else:
    s = s + str(i) + "="
    i=i+1

    print(s,sum)

    ReplyDelete
  63. num=int(input("enter number to caculate table"))
    i=1
    while(i<=10):
    print(str(num) + "*"+ str(i) + "=" + str(num*i))
    i=i+1

    ReplyDelete
  64. i=1
    while(i<=10):
    if i<=5:
    print(i)
    else:
    print(11-i)
    i=i+1

    ReplyDelete
  65. start = int(input('enter starting point'))
    end = int(input('enter ending point'))

    i=start
    while(i<end):
    s=i*i
    c=i*i*i
    print(i,s,c)
    i=i+1

    ReplyDelete
  66. cout = 0
    while count < 4:
    print('welcome to python')
    count += 1

    ReplyDelete
  67. # PYTHON(6 to 7 PM BATCH)

    print("i","\t","j")
    for i in range(1,6):

    for j in range(2,1,-1):
    j=6-i
    print(i,end='')
    print("\t",j)

    # OUTPUT
    i j
    1 5
    2 4
    3 3
    4 2
    5 1

    ReplyDelete
  68. # PYTHON(6 to 7 PM BATCH)
    # Using Nested For Loop

    for i in range(6,1,-1):
    print("\n")
    for j in range(1,8-i):
    print(j,end='')

    #OUTPUT
    1

    12

    123

    1234

    12345

    ReplyDelete
  69. #WAP to check prime number?
    num = int(input("Enter number to check prime number = "))
    i =1
    count = 0

    while i<=num:
    if num % i==0:
    count = count + 1
    i =i+1

    if count == 2:
    print(str(num) +" is a prime number")
    else:
    print(str(num) +" is not prime number")

    ReplyDelete
  70. #WAP to print 1 to 5 and 5 to 1 again 1 to 5 and 5 to 1 using a single while loop?
    i =1

    while(i<= 20):
    if i<=5:
    print(i)
    elif i <=10:
    print(11-i)
    elif i<=15:
    print(i-10)
    else:
    print(i-15)
    i = i+1

    ReplyDelete
  71. #WAP to print 1 to 5 and 5 to 1 again 1 to 5 and 5 to 1 using a single while loop?
    i =1

    while(i<=20):
    if i<= 5:
    print(i)
    elif i>5 and i<=10:
    print(11-i)
    elif i>10 and i<= 15:
    print(i-10)
    else:
    print(21-i)
    i =i +1

    ReplyDelete
  72. #WAP to perform the addition of a one-digit positive number?
    sum =0
    i =1
    s =''

    while(i<=10):
    sum = sum + i
    if i<10:
    s = s+str(i) +"+"
    else:
    s= s+str(i) + "="
    i = i+1

    print(s,sum)

    ReplyDelete
  73. #WAP to reverse any digit number?
    num = int(input("Enter number = "))
    s = ''
    while(num!=0):
    s = s+ str(num%10)
    num = num//10
    else:
    print(s)

    ReplyDelete
  74. #WAP to check prime number using While--else statement in Python?
    num = int(input("Enter number = "))
    i = 2
    while i <num:
    if num %i ==0:
    print(str(num)+" Is Not Prime")
    break
    i =i+1
    else:
    print(str(num) +" Is Prime")

    ReplyDelete
  75. #WAP to calculate factorial of any number?
    num = int(input("Enter number = "))
    i = num
    f = 1
    #s= ''

    while( i>= 1):
    f = f * i
    #s = s +str(i) + "*"
    i=i-1

    print("factorial of "+ str(num)+" = "+ str(f))

    ReplyDelete
  76. #WAP to print a table of odd numbers?
    num = int(input("Enter number"))
    if num%2!=0:
    for i in range(1,11):
    print(str(num) + " * " + str(i) + "="+str(num*i))

    else:
    print("Enter odd number")

    ReplyDelete
  77. #WAP to display fibonacci series?
    a = -1
    b = 1

    for i in range(1,11):
    c= a+b
    print(c)
    a=b
    b=c

    ReplyDelete
  78. #WAP to calculate factorial of any number with complete expression?
    n = int(input("Enter number"))
    f= 1
    s=''

    for i in range(n, 1,-1):
    f =f*i
    s = s +str(i) +"*"

    print(str(s)+"1="+str(f))

    ReplyDelete
  79. #WAP to calculate the sum of one digit positive number?
    s = int(input("Enter number"))
    for i in range(1,s):
    s = s+i


    else:
    print(s)

    ReplyDelete
  80. #NESTED FOR LOOP
    for i in range(10,0,-1):
    for j in range(1, i+1):
    print(j,end='')
    print()

    ReplyDelete
  81. # nested_for_loop
    for i in range(1 ,6):
    for j in range(1,7-i):
    print( j, end='')
    print()

    ReplyDelete
  82. #Nested_for-loop_ABCDE_abcd
    for i in range(70,65,-1):
    for j in range(65,i):
    if i%2==0:
    print(chr(j),end='')
    else:
    print(chr(j+32), end='')
    print()

    ReplyDelete
  83. for i in range(65, 91):
    for j in range(65, i+1):
    print(chr(j), end='')
    print()

    ReplyDelete
  84. for i in range(70,65,-1):
    for j in range(65, i):
    if j %2 != 0:
    print(chr(j), end='')
    else:
    print(chr(j+32), end='')
    print()

    ReplyDelete
  85. #Nested_loop AaBbC

    for i in range(70, 65, -1):
    t = 65
    for j in range(65,i):
    if j%2 !=0:
    print(chr(t), end='')
    t =t+1
    else:
    print(chr(t+32), end='')
    print()

    ReplyDelete
  86. for i in range(1,6):
    for j in range(1, 7-i):
    if i % 2==0:
    print(6-j, end='')
    else:
    print(j, end='')
    print()

    ReplyDelete
  87. ABHISHEK GOYAL
    for i in range(70,65,-1):
    k=65
    for j in range(65,i):
    if j%2==0:
    print(chr(k+32),end=' ')
    k=k+1
    else:
    print(chr(k),end=' ')

    print()

    ReplyDelete
  88. ABHISHEK GOYAL
    for i in range(70,65,-1):
    k=65
    for j in range(65,i):
    if j%2==0:
    print(chr(k+32),end=' ')
    k=k+1
    else:
    print(chr(k),end=' ')

    print()

    ReplyDelete
  89. ABHISHEK GOYAL
    for i in range(70,65,-1):
    k=65
    for j in range(65,i):
    if j%2==0:
    print(chr(k+32),end=' ')
    k=k+1
    else:
    print(chr(k),end=' ')

    print()

    ReplyDelete
  90. ABHISHEK GOYAL
    for i in range(0,5):
    ch=65
    for k in range(0,i):
    print(' ',end=' ')
    ch=ch+1
    for j in range(i,5):
    print(chr(ch),end=' ')
    ch=ch+1

    print()

    ReplyDelete
  91. import time

    print("Please insert Your CARD")

    #for card processing
    time.sleep(5)

    password = 1234

    #taking atm pin from user
    pin = int(input("enter your atm pin "))

    #user account balance
    balance = 5000

    #checking pin is valid or not
    if pin == password:
    #loop will run user get free
    while True:

    #Showing info to user

    print("""
    1 == balance
    2 == withdraw balance
    3 == deposit balance
    4 == exit
    """
    )

    try:
    #taking an option from user
    option = int(input("Please enter your choise "))
    except:
    print("Please enter valid option")

    #for option 1
    if option == 1:
    print("Your current balance is",{balance})

    if option == 2:

    withdraw_amount = int(input("please enter withdraw_amount "))



    balance = balance - withdraw_amount

    print({withdraw_amount},"is debited from your account")



    print("your updated balance is",{balance})



    if option == 3:

    deposit_amount = int(input("please enter deposit_amount"))

    balance = balance + deposit_amount



    print({deposit_amount},"is credited to your account")



    print("your updated balance is",{balance})



    if option == 4:

    break


    else:
    print("wrong pin Please try again")

    ReplyDelete
  92. # PYTHON (6 To 7 PM BATCH)
    # CODE to Calculate Factorial of a Number with Complete Expression.

    a = int(input("Enter The Number:-"))

    b = 1
    for i in range(1,a+1):
    if i <a:
    b=i*b
    print(i,"*",end='')
    if i==a:
    b=i*b
    print(i,"=",b)

    ReplyDelete
  93. # PYTHON( 6 To 7 PM BATCH)
    # Code to reverse any digit number.

    a =int(input("Enter The Number :-\t"))

    b = str(a)

    c = str()

    for i in b:
    c=i +c
    a= int(c)

    print("Digit after reverse:-",a)

    ReplyDelete

Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post