Write a Python program to find the second largest number in a list. Example - 1 : Example - 2 : Example - 3 : Example - 4 : Sample Solution:- Python Code: Sample Output: Flowchart: The following tool visualize what the computer is doing step-by-step as it executes the said program: Python Code Editor: Have another way to solve this solution? Contribute your code (and comments) through Disqus. Previous: Write a Python program to find the second smallest number in a list.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
How to delete a file or folder?
Path objects from the Python 3.4+ pathlib module also expose these instance methods:
Ref: https://bit.ly/2zFlhuR
This article is created to cover some programs in Python, that find and prints second largest number or element in a given list. Here are the list of programs covered in this article:
Find Second Largest Number in List without using FunctionThe question is, write a Python program that find second largest element in a list using for loop. Here is its answer: nums = [] print("Enter 10 Elements (Numbers) for List: ") for i in range(10): nums.append(int(input())) large = nums[0] for i in range(10): if large<nums[i]: large = nums[i] secondLarge = nums[0] for i in range(10): if secondLarge<nums[i]: if nums[i]!=large: secondLarge=nums[i] print("\nSecond Largest Number is: ") print(secondLarge) Here is its sample run:
Subscribe to his free Masterclasses at Youtube & technical discussions at Telegram SanfoundryClasses. |