Firstly the issue you have with your statement is that when you perform boolean logic (and
/or
statements here) is that it is evaluated as an expression.
Take the third line in which you have:
if (bolivia == "La Paz" or "Sucre"):
Here you have the boolean logic operator or
. This means it will evaluate each side (or rather is will evaluate the first side.. if that is correct it ignores the second statement.. but that is just a tidbit of extra information).
bolvia == "La Paz"
is a valid expression. You are asking if bolvia is equal to the string "La Paz".
"Sucre"
is not a valid statement. It has no meaning, you must form this into an expression also.
bolvia == "La Paz" or bolvia == "Sucre"
would be two correct expressions that could be evaluated by an or
statement.
Now you should have the intended behaviour of your if
statement.
I would recommend making this more foolproof also by making it case-insensitive. By this I mean you could change the string into the proper format before testing. This would allow for "sucre"
, "la paz"
and other possibilities.
This would change your initial statement to
bolivia = str(input("Name a capital of Bolivia.")).title()
Now in your test statements you could enter la paz
and then receive La Paz
as an output.
score = score + 50
can also be shortened to score += 50
as this is a shorthand for the former.
This would change your code to the following:
score = 0
bolivia = str(input("Name a capital of Bolivia.")).title()
if (bolivia == "La Paz" or bolivia == "Sucre"):
print ("Correct")
score += 50
print (score)
else:
print ("You/re incorrect")
input ("Press enter to exit;)")
Hope this helps.