11/26/23, 4:53 AM Basic Python Program - Jupyter Notebook
localhost:8888/notebooks/Piush Kumar Sharma/Basic Python Program.ipynb 74/95
Program 116
Create a function that takes a list of numbers between 1 and 10 (excluding one
number) and returns the missing number.
Examples
missing_num([1, 2, 3, 4, 6, 7, 8, 9, 10]) ➞ 5
missing_num([7, 2, 3, 6, 5, 9, 1, 4, 8]) ➞ 10
missing_num([10, 5, 1, 2, 4, 6, 8, 3, 9]) ➞ 7
In [144]:
In [145]:
In [146]:
In [147]:
Program 117
Write a function that takes a list and a number as arguments. Add the number to the
end of the list, then remove the first element of the list. The function should then
return the updated list.
Examples
next_in_line([5, 6, 7, 8, 9], 1) ➞ [6, 7, 8, 9, 1]
next_in_line([7, 6, 3, 23, 17], 10) ➞ [6, 3, 23, 17, 10]
next_in_line([1, 10, 20, 42 ], 6) ➞ [10, 20, 42, 6]
next_in_line([], 6) ➞ "No list has been selected"
Out[145]:5
Out[146]:10
Out[147]:7
def missing_num(lst):
total_sum = sum(range(1, 11)) # Sum of numbers from 1 to 10
given_sum = sum(lst) # Sum of the given list of numbers
missing = total_sum - given_sum
return missing
missing_num([1, 2, 3, 4, 6, 7, 8, 9, 10])
missing_num([7, 2, 3, 6, 5, 9, 1, 4, 8])
missing_num([10, 5, 1, 2, 4, 6, 8, 3, 9])
1
2
3
4
5
1
1
1