w3resource logo


Python Exercises

Python Challenges: Find a missing number from a list

Python Challenges - 1: Exercise-7 with Solution

Write a Python program to find a missing number from a list.

Input : [1,2,3,4,6,7,8]
Output : 5

Explanation :

Python: missing number from a list

Sample Solution :-

Python Code :

def missing_number(num_list):
    return sum(range(num_list[0],num_list[-1]+1)) - sum(num_list)

print(missing_number([1,2,3,4,6,7,8]))

print(missing_number([10,11,12,14,15,16,17]))

Output :

5                                                                       
13

Flowchart:

Python Flowchart: Find a missing number from a list

Python Code Editor:

def missing_number(num_list):
    return sum(range(num_list[0],num_list[-1]+1)) - sum(num_list)

print(missing_number([1,2,3,4,6,7,8]))

print(missing_number([10,11,12,14,15,16,17]))

Improve this sample solution and post your code through Disqus



Join our Question Answer community to learn and share your programming knowledge.

Solve these problems:

Java: How to convert a string to an integer in Java?

C#: Loops in c#

SQL: JOIN using more than 5 tables