On 02/06/15 02:35, Stephanie Quiles wrote:

import pickle

You don;t need pickle

def main():
     right = 0
     wrong = 0
     capitals = {'Alabama': 'Montgomery', 'Alaska': 'Juneau', \
  \
                "Arizona": 'Phoenix', \

You don't need the \
Inside {} you can put newlines as much as you like:


                 'Arkansas': 'Little Rock', 'California': 'Sacramento',
                 'Colorado': 'Denver',      'Connecticut': 'Hartford',
                 'Delaware': 'Dover',       'Florida': 'Tallahassee',
etc...


     for k in capitals.keys():
         state = input('Enter the capital of '+k+' :')

This loop just keeps reading the inputs but does nothing with them.
I suspect you intended to have the following lines inside the loop?

     if state.upper() == capitals[k].upper():
         right += 1
         print('Correct')
     else:
         wrong += 1
         print('Incorrect')
     choice = input('Do you want to play again y/n: ')
     if choice.upper() == 'N':
         print('end of game')

You need to provide a mechanism for exiting the loop.
The break statement can do that for you.


     else:
         choice.upper() != 'Y'
         print("invalid choice")

     print('Number of correct answers is: ', right)
     print("Number of incorrect answers is:", wrong)

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to