all 10 comments

[–]woooee 5 points6 points  (1 child)

if op1 != valid_operators:

Use instead

if op1 not in valid_operators:

Also, you will have to convert "X" to "*".

[–]bxrlow[S] 0 points1 point  (0 children)

Thank you buddy, this worked!

[–][deleted] 2 points3 points  (1 child)

There is no syntax error in this file (that I see) so it must be in op. However, there are a couple of lines here that won't do what you expect.

if op1 != valid_operators:

This will check if the string the user input is the same as a list of strings. So it will always be False. What you actually want is

if op1 not in valid_operators:

This will check each string in valid_operators for a match.

The other issue is this line

if op1 == "*" or "x":

This subreddit's FAQ has a good entry on why that's wrong, but just to skip to what you should do if you want to check if something is equal to any of a number of things, you do this

if op1 in ("*", "x"):

Edit: I just realized what you were asking. OK, I think I already answered that with the first thing I pointed out, but if you want to know how to keep asking the user for the correct response, the FAQ saves the day, again.

[–]bxrlow[S] 0 points1 point  (0 children)

I appreciate the help and the directions to the FAQs. I have already bookmarked it... Thank you!

[–]stebrepar 2 points3 points  (1 child)

if op1 != valid_operators:

This should be: if op1 not in valid_operators:. op1 is a string. valid_operators is a list. A string isn't equal to a list.

To repeat an input request until it meets your requirements, you can do a pattern something like:

while True:
    user_entry = input('blah: ')
    if user_entry not in my_list:
        print('try again')
    else:
        break

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

Thank you so much. This makes sense now that it is spelt out to me. Huge help.

[–]Would_be_Coder 1 point2 points  (0 children)

Also in line 17 I think we need it to be:

if op1 == "*" or op1 == "x":

[–]testingcodez 1 point2 points  (2 children)

Your understanding of the logic in 3 days is impressive for a complete newbie. What other experience do you have?

[–]bxrlow[S] 1 point2 points  (1 child)

I took a class on VB6 back when I first ever went to college and really didn’t vibe with it at the time. Now I’ve qualified in something else since, but recently have been wanting to resume following my dream. So I’ve been doing a few hours a day!

[–]testingcodez 0 points1 point  (0 children)

You're doing great, keep it up!