Q. Write a program to input N number and then print the second largest number.


You can understand by Watching video :-



Answer :-

largest = 0
second = 0
while True :
    a = int(input("enter a number (for quit enter 0 (zero) )= "))
    if a == 0 or a== 0 :
        break
    else :
        if a  > largest :
            second = largest
            largest  = a
            
print(second,"is second biggest number ")

Output :-

Enter a number (for quit enter 0 (zero) )= 9
Enter a number (for quit enter 0 (zero) )= 8
Enter a number (for quit enter 0 (zero) )= 7
Enter a number (for quit enter 0 (zero) )= 6
Enter a number (for quit enter 0 (zero) )= 5
Enter a number (for quit enter 0 (zero) )= 4
Enter a number (for quit enter 0 (zero) )= 3
Enter a number (for quit enter 0 (zero) )= 2
Enter a number (for quit enter 0 (zero) )= 1
Enter a number (for quit enter 0 (zero) )= 0
8 is second biggest number

>>> 

Enter a number (for quit enter 0 (zero) )= 5678
Enter a number (for quit enter 0 (zero) )= 42
Enter a number (for quit enter 0 (zero) )= 59
Enter a number (for quit enter 0 (zero) )= 41
Enter a number (for quit enter 0 (zero) )= 86
Enter a number (for quit enter 0 (zero) )= 95
Enter a number (for quit enter 0 (zero) )= 36
Enter a number (for quit enter 0 (zero) )= 0
95 is second biggest number

>>>

7 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. There is an error if you arrange the numbers in ascending order for example 1,2,3.

    ReplyDelete
  2. Please tell us how you created this website by posting a video on YouTube at your channel🙂

    ReplyDelete
  3. hii bro big fan

    ReplyDelete
  4. n=int(input("No of numbers"))
    max1=0
    max2=0
    for a in range(n):
    c=int(input("Enter numbers to compare"))
    if c>max1:
    b=max1
    max1=c
    if cmax2:
    max2=c
    if b>max2:
    max2=b
    print(max2)

    This one is more accurate . its in for loop you can change it to while

    ReplyDelete
    Replies
    1. sorry for the indentations hope you will understand

      Delete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post