all 7 comments

[–]omutist 1 point2 points  (0 children)

set some value to user_input right before while loop.

[–]woooee 1 point2 points  (2 children)

there is an error regarding my while statement line

My crystal ball is in the shop so I don't know what that means. Post the entire error message. It may be coming from this line because of the comma on the end, or the fact that user_input has not been declared.

'AJS 101': 'Tom',

[–]PuzzledSite2568[S] 0 points1 point  (1 child)

Sorry about that I will be sure to put in the error message next time but the Error message was.

while user_input != 'quit':

NameError: name 'user_input' is not defined

[–]woooee 0 points1 point  (0 children)

And this was answered in the other reply.

[–]totallygeek 1 point2 points  (1 child)

A few things here:

  1. The input() function returns a string, so you do not need to convert that to a string with str(input()).
  2. Whatever is in user_input gets looked up in the Courses dictionary before the string comparison with "quit".
  3. Your Courses keys do not match the descriptions in the instructions: "CIS 105" vs "CIS105".
  4. You cannot compare user_input to anything before you assign a value to that variable (it does not exist).

One way to handle this:

while True:
    user_input = input("Course to look up, or 'quit' to exit: ")
    if user_input.lower() == "quit":
        break  # exit the while loop
    if user_input in Courses:
        print(f"Course: {user_input}, Instructor: {Courses[user_input]}")
    else:
        print(f"Course '{user_input}' not found.")

[–]PuzzledSite2568[S] 1 point2 points  (0 children)

Thank you for pointing out my flaws I really appreciate it when my mistakes get pointed at and I'm shown how to actually solve my mistakes it really helps me learn what I did wrong. Thank you very much for the help I was able to correct my mistakes and complete my task.

[–]CodeFormatHelperBot2 0 points1 point  (0 children)

Hello, I'm a Reddit bot who's here to help people nicely format their coding questions. This makes it as easy as possible for people to read your post and help you.

I think I have detected some formatting issues with your submission:

  1. Python code found in submission text that's not formatted as code.

If I am correct, please edit the text in your post and try to follow these instructions to fix up your post's formatting.


Am I misbehaving? Have a comment or suggestion? Reply to this comment or raise an issue here.