-4

Could someone please give me advice of how to start my code? I am supposed to verify if a text document containing rows of 9 numbers do have all 9 digits. If so, my code should say True, otherwise False.

Here is one of the text document examples

5,3,4,2,7,6,9,1,8
6,2,8,1,9,5,3,4,7
1,7,9,3,4,8,5,6,2
8,5,2,7,6,1,4,9,3
4,9,6,8,5,3,7,2,1
7,1,3,9,2,4,8,5,6
9,6,1,5,3,7,2,8,4
2,8,6,5,1,9,6,3,5
3,4,5,6,8,2,1,7,9

Code must say False Thank you very much

Michelle
  • 1
  • 4

1 Answers1

1

You could do something like this (ofcourse you need to read from file and that's left to you):

s = '''5,3,4,2,7,6,9,1,8
6,2,8,1,9,5,3,4,7
1,7,9,3,4,8,5,6,2
8,5,2,7,6,1,4,9,3
4,9,6,8,5,3,7,2,1
7,1,3,9,2,4,8,5,6
9,6,1,5,3,7,2,8,4
2,8,6,5,1,9,6,3,5
3,4,5,6,8,2,1,7,9'''

for x in s.split('\n'):
    print(''.join(sorted(x.split(','))) == '123456789')

# True
# True                                                        
# True                                                        
# True                                                        
# True                                                        
# True                                                        
# True                                                       
# False                                                       
# True

This checks whether each line contains all numbers from 1 to 9 in any order, giving out a True in that case else a False.

Austin
  • 25,759
  • 4
  • 25
  • 48