I'm writing a program to see which input.txt has all the numbers from 0 to 99. Here's the program you've written.
fname=input('Enter a file name:')
try: fhand=open(fname)
except: print('File cannot be opend',fname)
quit()
strnumbers=fhand.read().split()
for k in range(0,100):
for num in strnumbers:
if num is not k:
print('False')
But even my teeth aren't working (Crying)
My teacher told me to put this as inCovered=99*[False] and change False to True whenever there is a number one by one, but I actually didn't learn the boolean concept, so I don't know how to do it. Even if it's not the boolean method, is there a way to make all the numbers come out by looking at the program I wrote above?
boolean
strnumbers=fhand.read().split()
strnumbers.sort()
print(strnumbers)
for k in range(0,100):
if k != int(strnumbers[k]):
print "False"
break
I think that's about it. However, this code will raise the index error if the length of strnumbers is less than 100.
For Python lectures, you can watch Kim left-handed coding or Programmers-Python Introduction.
© 2024 OneMinuteCode. All rights reserved.