#๐ unknown problem with code
35 messages ยท Page 1 of 1 (latest)
@stuck summit
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.
this save_data() call here is actually going to cause massive issues
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
alternatives?
(im relatively new to programming so most of what i have learned so far would be entry-level)
what errors are you encountering that you felt like you had to use try/except to solve?
most errors you encounter will have real solutions instead of dusting them under the rug
i wouldn't say i was encountering any errors prior
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)
then what are the try/excepts for?
@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.")
means to an end? ๐ญ
you might have to scale back your questions a bit im sorry
questions help give us insight into your thought process and skill level
to be frank, a lot of this was genai because crunched for time
๐ฅด
yeah
again, means to an end ๐
my current course is very crunchy and thus there's a lot of stuff/assignments to complete within a week's time (no weekends at all)
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
how did students get by before genai? ๐ค
they asked people
@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)
if you let AI do the work for you, you will be in trouble when you really need to know this stuff yourself, like during a test (and that is if you are not found out before that)
that much i understand, yeah
just trying to make sure i get this current ordeal done with and resort less to genai
it's going to code you into a corner though with messy code that you don't understand
the first problem i pointed out is prevalent though out the code almost at every point where there is a try/except
@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.")
sorry, was working through fixing the code with someone else
as for this the fragment has made_change for every if statement in the block
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.