#๐Ÿ”’ unknown problem with code

35 messages ยท Page 1 of 1 (latest)

stuck summit
#

Program in question is a music school management system (uni assignment)
When run, it's supposed to take me back to the "main menu" so I can select another option but it just stops like in pic related

Code:
https://paste.pythondiscord.com/ON5A

steel muskBOT
#

@stuck summit

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

wind shoal
#

it will overwrite your data on program start

#

if you want "one final save on exit", it has to come after main()

#

I'd also recommend not relying so heavily on try/except. It's masking a lot of errors you might be encountering which makes it so much harder to track down issues

stuck summit
#

(im relatively new to programming so most of what i have learned so far would be entry-level)

wind shoal
#

most errors you encounter will have real solutions instead of dusting them under the rug

stuck summit
#

try/except was just a means to finish the code (context: my assignment has fragments of unfinished code that we need to put together and complete)

wind shoal
#

then what are the try/excepts for?

robust zenith
#

@stuck summit try to keep the try block as specific as possible (in most cases)
here only one line needs to be inside it instead of this:

        if choice == '1': # check in student.
        # Gets student_id and course_id from user, then calls check_in().
            try:
                student_id = int(input("Enter Student ID: "))
                course_id = input("Enter Course ID: ").strip()
                check_in(student_id, course_id)
                made_change = True
            except ValueError:
                print("Invalid Student ID.")
stuck summit
#

means to an end? ๐Ÿ˜ญ

you might have to scale back your questions a bit im sorry

wind shoal
stuck summit
#

to be frank, a lot of this was genai because crunched for time

wind shoal
#

๐Ÿฅด

stuck summit
#

yeah

wind shoal
#

I wouldn't touch ai as someone learning to code

#

stay far away

stuck summit
wind shoal
#

and rndpkt is exactly right above. It's ok to use try/except to handle the int input, but that should be the only thing within the try/except

wind shoal
stuck summit
robust zenith
#

@stuck summit also be aware of that the last line here will run no matter if an exception happend or not

        elif choice == '2': # print student card
            # Gets student_id, then prints calls print_student_card()
            try:
                student_id = int(input("Enter Student ID: "))
                print_student_card(student_id)
            except ValueError:
                print("Invalid Student ID.")
            made_change = True
```and why would `made_change` ever need to be set when only printing a student card? (as i'm guessing that shouldn't modify any data you should not need to save any data an additional time after this)
robust zenith
stuck summit
wind shoal
#

it's going to code you into a corner though with messy code that you don't understand

robust zenith
#

@stuck summit this part does nothing other then print out the text, but it doesn't exit the loop

        elif choice.lower() == 'q':
            print("Saving final changes and exiting.")
stuck summit
stuck summit
steel muskBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.