Please save me. Boolean, I have a questionPlease save me(Crying)

Asked 2 years ago, Updated 2 years ago, 137 views

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

2022-09-22 18:56

1 Answers

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.


2022-09-22 18:56

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.