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.
Explanation:
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]))
Sample Output:
5 13
Flowchart:
Python Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a Python program to check if a number is a power of a given base.
Next: Write a Python program to find missing numbers from a list.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/python-exercises/challenges/1/python-challenges-1-exercise-7.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics