Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

First, please use if __name__ == "__main__":. This will help you if you ever decide to split your program up into multiple files, and I think it is time you did. It is quite cluttered the way it is, and you could have one file per supported feature - one for the calculator, one for the hangman game, etc. You can read specifics about why you should use this here here.

First, please use if __name__ == "__main__":. This will help you if you ever decide to split your program up into multiple files, and I think it is time you did. It is quite cluttered the way it is, and you could have one file per supported feature - one for the calculator, one for the hangman game, etc. You can read specifics about why you should use this here.

First, please use if __name__ == "__main__":. This will help you if you ever decide to split your program up into multiple files, and I think it is time you did. It is quite cluttered the way it is, and you could have one file per supported feature - one for the calculator, one for the hangman game, etc. You can read specifics about why you should use this here.

Source Link
user34073
user34073

First, please use if __name__ == "__main__":. This will help you if you ever decide to split your program up into multiple files, and I think it is time you did. It is quite cluttered the way it is, and you could have one file per supported feature - one for the calculator, one for the hangman game, etc. You can read specifics about why you should use this here.

Second, please use more methods! I would have one method print the news, one print help prompts, one call the other .EXE files (or pretend .EXE files), and so on. Also, we don't need the welcome each time it loops, it should be displayed one time when the program is opened. If you used more methods, this section would be a lot cleaner, a lot smaller, and a lot easier to debug.

while True:
 os.system('cls' if os.name == 'nt' else 'clear')
 print ()
 print ("PyDOS VERSION 1.9.5")
 shell = input("> ")
 if shell == "textviewer":
 print ("Loading Text Viewer...")
 time.sleep(3)
 textviewer()
 elif shell == "help":
 print ("HELP")
 print ("-----------------")
 print ("Commands:")
 print ("dir - displays directory.")
 print ("cls - clears screen")
 print ("help - shows help")
 print ("textviewer - launches textviewer")
 print ("edit - launches edit")
 print ("news - launches news")
 print ("shutdown - closes PyDOS")
 print ("calc - launches calculator")
 print ("------------------------------------")
 print ("What is PyDOS?")
 print ("PyDOS is inspired by MS-DOS made in the 1980's and")
 print ("has that feel of it too! For a better experiance")
 print ("run PyDOS in the python CMD shell.")
 input ("Press enter to close.")
 elif shell == "edit":
 print ("Loading edit...")
 time.sleep(3)
 edit()
 elif shell == "calc":
 calc()
 elif shell == "dir":
 print ("The drive name is A:")
 print ()
 print ("NAME: TYPE: MODIFIED:")
 print ("SHUTDOWN.EXE .EXE 12/01/15 ")
 print ("EDIT.EXE .EXE 09/03/15 ")
 print ("TEXTVIEWER.EXE .EXE 09/03/15 ")
 print ("NEWS.EXE .EXE 09/01/15 ")
 print ("HELP.COM .COM 09/03/15 ")
 print ("HANGMAN(BROKEN).EXE .EXE 11/03/15 ")
 print ("CALC.EXE .EXE 20/03/15 ")
 input ("---------------Press enter to close---------------")
 elif shell == "cls":
 cls()
 elif shell == "hangman":
 hangman.main()
 elif shell == "news":
 print ("PyDOS NEWS")
 print ()
 print ("New Additions:")
 print ()
 print ("New calculator app!")
 print ("All text documents from edit are now stored in a 'files' directory")
 print ()
 print ("Tweaks and fixes:")
 print ()
 print ("BUG023L: Fixed issue with splash screen loop")
 print ()
 print ("Reported Bugs:")
 print ("BUG024T: Hangman returns a traceback error, we are fixing this!")
 print ("BUG025T: Pressing 'y' in texteditor when it asks you if you want\nto edit the file returns Type_Error")
 input("Press enter to close")
 elif shell == 'shutdown':
 print ("Shutting down...")
 time.sleep(3)
 break
 else:
 print("This command or file: "+shell+ " does not exist. Check for spelling errors and try again.\nIf you are trying to open a textfile, open textviewer.")
 time.sleep(5)
 os.system('cls' if os.name == 'nt' else 'clear')

You could, for example, do this instead:

elif shell == "help":
 help()

Third, don't sleep your program. You never want your program lagging for no apparent reason - especially when the user knows it shouldn't.

Fourth, I would print a list of valid inputs when the program is first run, not leave the user looking at a blank screen and wondering what to do next.

lang-py

AltStyle によって変換されたページ (->オリジナル) /