Python. Sets
I made a program, everything works, but if 1 task still outputs normally, then 2 does not, because you need the numbers to be in ascending order. Maybe I'm not handling numeric sets correctly.
Task: there is a set of integers {1,2,3,4,5,6,7,8,9} 1)Make a function that will count the number of unique digits in the number n. 2) Outputs in ascending order all the digits that are not present in the number n
My code:
n = input("Число: ")
a = {"1", "2", "3", "4", "5", "6", "7", "8", "9"}
result=list(set(a) & set(n))
print(len(result))
result1=list(set(a)-set(result))
print(result1)
0
1 answers
If I understood the problem correctly then so:
num = input()
task1 = len(set(num))
task2 = sorted(set('0123456789') - set(num))
print(task1)
print(*task2)
2
Author: Zhihar, 2021-01-07 19:17:48