186k views
5 votes
8.4 (1%) Write a program that checks if all the input numbers cover 1 to 99. Each ticket for the Pick-10 lotto has 10 unique numbers ranging from 1 to 99. Suppose you buy a lot of tickets and like to have them cover all numbers from 1 to 99. Write a program that reads the ticket numbers from a file and checks whether all numbers are covered. Assume the last ending number in the file is 0. Suppose the file contains the numbers 80 3 87 62 30 90 10 21 46 27 12 40 83 9 39 88 95 59 20 37 80 40 87 67 31 90 11 24 56 77 11 48 51 42 8 74 1 41 36 53 52 82 16 72 19 70 44 56 29 33 54 64 99 14 23 22 94 79 55 2 60 86 34 4 31 63 84 89 7 78 43 93 97 45 25 38 28 26 85 49. 47 65 57 67 73 69 32 71 24 66 92 98 96 77 6 75 17 61 58 13 35 81 18 15 5 68 91 50 76 0 Your program should display The tickets cover all numbers. Suppose the file contains the numbers 11 48 51 42 8 74 1 41 36 53 52 82 16 72 19 70 44 56 29 33 0 Your program should display The tickets don't cover all numbers 2

1 Answer

6 votes

Here is the Python program that checks if all the input numbers cover 1 to 99:```pythonwith open("input.txt") as file:
numbers = file.read().split()
numbers = list(map(int, numbers))
all_numbers = set(range(1, 100))
ticket_numbers = set(numbers)

if all_numbers == ticket_numbers:
print("The tickets cover all numbers.")
else:
print("The tickets don't cover all numbers.")```The program first reads the numbers from the input file and converts them to integers. Then it creates two sets: one with all the numbers from 1 to 99 and the other with the ticket numbers. It then checks if the two sets are equal.

If they are, it means that all the numbers from 1 to 99 are covered and the program prints "The tickets cover all numbers." If they are not equal, it means that some numbers are missing and the program prints "The tickets don't cover all numbers."

User Waseemwk
by
8.0k points