Computer Science
Write a program to input N numbers and then print the second largest number.
Python
Python Control Flow
37 Likes
Answer
n = int(input("How many numbers you want to enter? "))
if n > 1 :
l = int(input()) # Assume first input is largest
sl = int(input()) # Assume second input is second largest
if sl > l :
t = sl
sl = l
l = t
for i in range(n - 2) :
a = int(input())
if a > l :
sl = l
l = a
elif a > sl :
sl = a
print("Second Largest Number =", sl)
else :
print("Please enter more than 1 number")
Output
How many numbers you want to enter? 5
55
25
36
12
18
Second Largest Number = 36
Answered By
10 Likes
Related Questions
Write a program to take N (N > 20) as an input from the user. Print numbers from 11 to N. When the number is a multiple of 3, print "Tipsy", when it is a multiple of 7, print "Topsy". When it is a multiple of both, print "TipsyTopsy".
Write a short program to find largest number of a list of numbers entered through keyboard.
Given a list of integers, write a program to find those which are palindromes. For example, the number 4321234 is a palindrome as it reads the same from left to right and from right to left.
Write a complete Python program to do the following :
(i) read an integer X.
(ii) determine the number of digits n in X.
(iii) form an integer Y that has the number of digits n at ten's place and the most significant digit of X at one's place.
(iv) Output Y.
(For example, if X is equal to 2134, then Y should be 42 as there are 4 digits and the most significant number is 2).