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
>>>
There is an error if you arrange the numbers in ascending order for example 1,2,3.
ReplyDeleteOk, I have fixed.
DeletePlease tell us how you created this website by posting a video on YouTube at your channel🙂
ReplyDeleteAt first we made Website then youtube.
Deletehii bro big fan
ReplyDeleten=int(input("No of numbers"))
ReplyDeletemax1=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
sorry for the indentations hope you will understand
DeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )