Answer to Question #319477 in Python for Psy

Question #319477



Find the missing number, which number is repeated 1 3 2 1 4



Output: repeated and missing number



1 4




1
Expert's answer
2022-03-28T11:01:06-0400

Enter the following set of codes:

# program to find the repeating and missing elements
def main():
    """Display repeating and missing elements."""
    values = [1, 3, 2, 1, 4]
    num_dict = {}
    total = len(values)

    for i in values:
        if i not in num_dict:
            num_dict[i] = True
        else:
            print("Repeated =", i)

    for i in range(1, total + 1):
        if i not in num_dict:
            print("Missing =", i)

main()

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