Can't fix this quiz problem

I’m making a quiz for a school project but it wont work not sure what is wrong here.

That’s invalid syntax. Perhaps you forgot a comma?

1 Like

Please use prefomatted text, the </> button rather then screen shots as that makes it possible for us to quote your code.

You write this to make a python tuple.

answers = (A B C D E)

But python expects the values to have a comma between each value like this:

answers = (A, B, C, D, E)

After you fix that you will find the code does not do what you expect on line 80.
You wrote this:

elif quest1s == A, C, D, E:

That is not valid python and you will see a syntax error.
I think that you wish to know if quest1s is any of the 4 remaining answers.
Which would need code like this:

elif quest1s in (A, C, D, E):

The in operator will return true if quest1s is in any of the values in the tuple (A, C, D, E).

2 Likes

The “is in any” sounds like 'a' in ('foo', 'bar') will be true, since 'a' is in 'bar'.

(And an else would seem more logical to me…)

ok, I did that and it worked, I changed some other stuff and know the problem is that it does not answer correct or incorrect it just ends the program. I don’t know how to use the </> button.

Thank you! I see that I was not clear enough.

FYI i did not want to fix any logic errors beyond the confusion over tuples.
I will leave that to the OP.

Assuming you can see the button then all you need to do is copy and paste the text from your editor between the marks:

```
type or paste code here
```

It sounds like you want to have a loop around some of your code so that the program keeps going until an exit condition happens.

Research while loops.

so how do i make it execute this

print("What is the smallest unit in life?: ")
print("A: organs")
print("B: cells")
print("C: organism")
print("D: tissues")
print("E: organ system")
print("-------------------   ")
quest1s = input("?: ")
A = ("organs")
B = ("cells")
C = ("organism")
D = ("tissues")
E = ("organ system")
answers = (A, B, C, D, E)
if quest1s == B :
    print("Correct, lets go on to the next question.")
elif quest1s == (A, C, D, E,):
    print("Incorrect, lets go on to the next question.")
    
    
    
    

As i said i expect you will want to use a while loop.

I expect you to research this and post an attempt that you have written.

like this

print("What is the smallest unit in life?: ")
print("A: organs")
print("B: cells")
print("C: organism")
print("D: tissues")
print("E: organ system")
print("-------------------   ")
A = ("organs")
B = ("cells")
C = ("organism")
D = ("tissues")
E = ("organ system")
answers = (A, B, C, D, E)
quest1s = input("?: ")
while quest1s != (A, B, C, D, E)
    quest1s = input("That is not A, B, C, D, or E, please try again?: ")
if quest1s == B :
    print("Correct, lets go on to the next question.")
elif quest1s == (A, C, D, E,):
    print("Incorrect, lets go on to the next question.")

    

Yes that sort of thing. Is it working as you want now?

When prompted do you expect the user to type a single letter or a word?

a single letter

Your code checks for the words not the letters. Can you see why?
So if you enter “organs” it will work but not if you enter “C”.
Hint: add print(answers) what do you see?


how do i fix that

I tried that but it does nothing

You’re expecting the user to enter a letter, so why are you checking whether the reply is the value of A, i.e. "organs", etc.?

Also, if you want to know whether is or isn’t in a tuple, use in or not in.

Please, please, please learn to use the preformatted text option!
As I type this its the 6th icon after Quote, bold, italic, hyperlink, and blockquote in the tool bar at the top of the box I’m typing this into.

The things you write in your code do not work the same way as English words. Many words in English, like “is”, are very ambiguous and imprecise, and not suitable for instructing a computer. In order to write programs with the correct logic, you must think about the logic carefully - about its actual meaning, not about the English words that you would use to explain it.

If you want to check if the user’s input is one of many values, then you cannot find that out by directly comparing using ==. When I say “the ball is red or green”, that doesn’t mean that there is some magical colour called “red or green”, and that the ball has that colour. But that is the only kind of test that == does.

Please read:

yes, it is a syntax error. I agree with @barry-scott. Try this.