-1

Trying to understand what I am doing wrong here. The output I get when I type in "ohio" or "amsterdam" (or any other variable) is

Votes:

Robert: 0
Yukio: 0
Andrew: 1

I want the location chosen by the user to give the specified contestant (votesA, votesY, votesR) a point.

favorite_places = {
        
    'Andrew': {
        'place1': 'Tokyo', 
        'place2': 'Amsterdam',
        },
        
    'Yukio': { 
        'place1': 'Osaka', 
        'place2': 'Kyoto', 
        },
        
    'Robert': {
        'place1': 'Ohio', 
        'place2': 'Queensland', 
        'place3': 'Auckland',
        }
}


print("Welcome to location quiz poller.\nThese are the contestants choice of favorite places." 
 "Please choose which place is the best, whoever has the most votes will win.")

votesA = 0
votesY = 0
votesR = 0

votinglist = []

for name, place in favorite_places.items():
    #one way to label, access and print nested dictionary values
    places = f"{place['place1']}\n{place['place2']}\n{place.get('place3', '')}\n" 
    print(f"{name}'s favorite places are: ")
    print(f"{places}") 


print("Which place is the best place?")
inp = input('Enter here: ')
inp = inp.lower()

if inp == 'tokyo' or 'amsterdam':
    votesA += 1

elif inp == 'osaka' or 'kyoto':
    votesY += 1

elif inp == 'ohio' or 'queensland' or 'auckland':
    votesR += 1
else:
    print('That is not a valid selection.  -closing program-')

print(f"Votes:\n\tRobert: {votesR}\n\tYukio: {votesY}\n\tAndrew: {votesA}\n\t")




jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
faust
  • 3
  • 1

1 Answers1

0

You're having problems due to your conditions.

When you say if inp == 'tokyo' or 'amsterdam':, you're actually saying in simplified English "if input is Tokyo, or there's a string Amsterdam." That is, you're not actually comparing inp to Amsterdam. "Amsterdam" will always evaluate to True, as will any string except empty ones.

What you want is something along the lines of:

if inp == 'tokyo' or inp == 'amsterdam':

or, even better:

if inp in ('tokyo', 'amsterdam'):
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
rmssoares
  • 175
  • 1
  • 11
  • 1
    Thanks rmssoares. That fixed it perfectly and it makes a lot more sense than what I was doing. You also taught me something new about Python, so thanks again! :) – faust Nov 25 '20 at 20:27
  • No problem! Always happy to help, @faust. – rmssoares Nov 25 '20 at 20:31