Answer to Question #242647 in Python for Rishi

Question #242647
Give a list of numbers write a program to print the smallest postive integer missing in the give numbers
1
Expert's answer
2021-09-27T01:17:07-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