Ask coding questions

← Back to all posts
1
I am having trouble understanding why this code isn't working, could someone please help me out?
Matt359 (0)

https://repl.it/@Matt359/My-Quiz I am having trouble understanding why this code isn't working, could someone please help me out?

Commentshotnewtop
3
lsambrook (284)

Try this :

B = banana
A = biscuit
C = input("Which Spider is The Deadliest? Is it option A, The biscuit? or option B the banana? "
if C == A
print("maybe")
else
print("maybe")

1
ash15khng (215)
print ("Which Spider is The Deadliest?")

print ("Is it option A, The Red Back?, or option B, The Funnel Web?")

if input is 'B' print ("Hi")
if input is 'A' print ("They are both very poisionous that makes them very deadly.")

So first, you have to understand that though Python is quite friendly in terms of syntax, writing proper English sentences doesn't work (lol).

To get input, you use input(), like this:

a = input("text that you want to display")

This sets a to whatever the user typed in.

Comparing for equality works like this:

if a == "hello":
    print("the user typed hello")

This checks if a was "hello", and if it is it runs the print statement.

So your code should be something like this:

print ("Which Spider is The Deadliest?")

d = input("Is it option A, The Red Back?, or option B, The Funnel Web?")

if d == 'B':
    print ("Hi")
if d == 'A':
    print ("They are both very poisionous that makes them very deadly.")
1
ash15khng (215)

@Matt359 If this helped, please mark it as the answer!

1
mwilki7 (111)

What is it you want your code to do?

1
Matt359 (0)

@mwilki7 I want it to have a quiz game, then I want it to display the answer and see if you got it wrong or right, for about 20 questions.

1
mwilki7 (111)

@Matt359
You could try pairing the question with an answer using pairs.
For instance:

q1 = ('What are clouds made of?', 'Water')
q2 = ('What is Aurora Borealis mean?', 'Northern Lights')
# q1[0] gets the question, q1[1] is the answer
# same thing for q2, q3...and so on

answer = input(q1[0])

if answer == q1[1]:
    print("Correct")
else:
    print("Incorrect")

answer = input(q2[0])

if answer == q2[1]:
    print("Correct")
else:
    print("Incorrect")