Code file running problem

Put the entire contents of any given Py file in a def main():. Otherwise you get errors:


Also I made a small mistake and since you are not using the function that I modified from InvisibleOne you should change line 1 to:

choice = int(input("Which file to run?\n1) calculator\n2) resume\n3) date_operation\n4) continueeven\n5) exeption1\n "))+1

Python starts counting at 0, so everything is 1 off. This accounts for that and fixes the problem.

1 Like

where do i define main? in the main.py or in the file im trying to open?

In every file you wish to open, put everything in that file in a def main(): (this will require indenting the whole thing) so that you can execute the file. I started doing this in the fork that I made, but I won’t do it for every one because I don’t have the time to and it’s your program. But look there to see how it’s done.

now its giving me this error

Literally everything must be indented. Use Ctrl A to select all text and Ctrl ] or Tab to indent it. Then, add def main(): (not indented) to line 1.

print("Hello world!")
# Becomes:
def main():
  print("Hello world!")
2 Likes

thank you, if i need help with anything ill ask you

1 Like

Huh, I never knew you could do that. That will come in handy later! I’ve always done one line at a time, which takes forever. Thanks!

@joecooldoo I also learned recently that Ctrl / turns the line you’re on into a comment. Universal on Replit.

also do you have discord? if yes please send it

No I do not. You can always message me in Ask. Just click on my profile picture.
image

ok thank you if i need anything ill be sure to tell you

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.