So for my half year project about pi I made a simple checking program, that opens a file that is stored in the same folder, and an input, then is compares those and checks how many are the same, and stops if one isn't.


Code:
data=open("PI100000.txt", 'r').read()
data2=input("Import number: ")

i = 0
while i < len(data) and i < len(data2) and data[i] == data2[i]:
    i += 1

printx=str(i)+" Decimals of PI are correct"
print(printx)
input("Press enter to exit...")


now, when running this in the regular python interpreter it closes basically instantly. when run in cmd it does work perfectly, (the inputs wait for enter key).

now why doesn't this work in the regular python interpreter?
Does the python interpreter show any errors?
It might not be able to find the file you ar eopening.

On a side note, you should probably close the file that you open, or use a with statement like this:

Code:

with open("PI100000.txt", "r") as f:
  data = f.read()


This means that the file isn't left open and vulnerable.
So I found out that it only works if the python interpreter is set as standard, (it was vscode and i used run with). a bit inconvenient, but at least it works now
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement