Answer to Question #178127 in Python for ankitha

Question #178127

Given a list of numbers, write a program to print the smallest positive integer missing in the given numbers.Input


The input will be a single line containing numbers separated by space.Output


The output should be a single line containing the smallest missing number from given numbers.Explanation


For example, if the input numbers are 3, 1, 2, 5, 3, 7, 7.

The number 1, 2, 3 are present. But the number 4 is not. So 4 is the smallest positive integers that is missing from the given numbers.

Sample Input 1

3 1 2 5 3 7 7

Sample Output 1

4

Sample Input 2

5 5 2 3 1 8 8 4

Sample Output 2

6




1
Expert's answer
2021-04-04T05:19:53-0400
""" Program to print the smallest positive integer missing in a given list of numbers.
"""

print('Sample Input:')
# String containing list of numbers
numbers = "3 4 7 2 9 5 1"
print(numbers)
# List containing numbers in string form
numberListStr = numbers.split(' ')
# Convert each item in list to integer
numberListInt = [int(number) for number in numberListStr]

smallestMissing = 1

while True:
    if smallestMissing not in numberListInt:
        # Smallest missing number has been found
        break
    smallestMissing += 1

print()
print('Sample Output:')
print(smallestMissing)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS