Skip to main content

Do you know the capitals of the USA?



Hi...
This is the code to make tests... in this case tests about capitals of USA.
I have been inspired by this guy
https://automatetheboringstuff.com/chapter8/

But the code is different from what he did... I don't write in an external file the test, but you can copy the output. Maybe I will post the version to create txt files with this test.


from random import shuffle

capitals = {'Alabama': 'Montgomery', 
       'Alaska': 'Juneau', 
       'Arizona': 'Phoenix', 
       'Arkansas': 'Little Rock', 
       'California': 'Sacramento', 
       'Colorado': 'Denver', 
       'Connecticut': 'Hartford', 
       'Delaware': 'Dover', 
       'Florida': 'Tallahassee', 
       'Georgia': 'Atlanta', 
       'Hawaii': 'Honolulu', 
       'Idaho': 'Boise', 
       'Illinois': 'Springfield', 
       'Indiana': 'Indianapolis', 
       'Iowa': 'Des Moines', 
       'Kansas': 'Topeka', 
       'Kentucky': 'Frankfort', 
       'Louisiana': 'Baton Rouge', 
       'Maine': 'Augusta', 
       'Maryland': 'Annapolis', 
       'Massachusetts': 'Boston', 
       'Michigan': 'Lansing', 
       'Minnesota': 'Saint Paul', 
       'Mississippi': 'Jackson', 
       'Missouri': 'Jefferson City', 
       'Montana': 'Helena', 
       'Nebraska': 'Lincoln', 
       'Nevada': 'Carson City', 
       'New Hampshire': 'Concord', 
       'New Jersey': 'Trenton', 
       'New Mexico': 'Santa Fe', 
       'New York': 'Albany', 
       'North Carolina': 'Raleigh', 
       'North Dakota': 'Bismarck', 
       'Ohio': 'Columbus', 
       'Oklahoma': 'Oklahoma City', 
       'Oregon': 'Salem', 
       'Pennsylvania': 'Harrisburg', 
       'Rhode Island': 'Providence', 
       'South Carolina': 'Columbia', 
       'South Dakota': 'Pierre', 
       'Tennessee': 'Nashville', 
       'Texas': 'Austin', 
       'Utah': 'Salt Lake City', 
       'Vermont': 'Montpelier', 
       'Virginia': 'Richmond', 
       'Washington': 'Olympia', 
       'West Virginia': 'Charleston', 
       'Wisconsin': 'Madison', 
       'Wyoming': 'Cheyenne'}


print("Do you know the capitals of USA?")

states = []

for state in capitals:
    states += [state]

shuffle(states)

answers = [capitals[i] for i in states]


for n in range(30):
    if states[n][0] in "H":
        article = "of the"
    else:
        article = "of"
    print("Which is the capital",article, states[n], "?")
    right = answers[n]
    r_copy = answers.copy()
    r_copy.pop(n)
    shuffle(r_copy)
    ris = []
    for i in range(3):
        ris += [r_copy[i]]
    ris += [right]
    shuffle(ris)
    for i in range(4):
        print(" - ",ris[i])
    print("Solution:",right)
    
Do you know the capitals of USA?
Which is the capital of Ohio ?
 -  Columbus
 -  Lincoln
 -  Helena
 -  Frankfort
Solution: Columbus
Which is the capital of Kentucky ?
 -  Frankfort
 -  Little Rock
 -  Montpelier
 -  Austin
Solution: Frankfort
Which is the capital of Tennessee ?
 -  Lincoln
 -  Juneau
 -  Montpelier
 -  Nashville
Solution: Nashville
Which is the capital of Wyoming ?
 -  Cheyenne
 -  Pierre
 -  Salt Lake City
 -  Springfield
Solution: Cheyenne
Which is the capital of Arizona ?
 -  Honolulu
 -  Phoenix
 -  Cheyenne
 -  Boston
Solution: Phoenix
Which is the capital of Oregon ?
 -  Honolulu
 -  Salem
 -  Lansing
 -  Hartford
Solution: Salem
Which is the capital of Missouri ?
 -  Albany
 -  Lansing
 -  Phoenix
 -  Jefferson City
Solution: Jefferson City
Which is the capital of Vermont ?
 -  Jefferson City
 -  Montpelier
 -  Saint Paul
 -  Cheyenne
Solution: Montpelier
Which is the capital of Utah ?
 -  Albany
 -  Salt Lake City
 -  Olympia
 -  Montgomery
Solution: Salt Lake City
Which is the capital of Virginia ?
 -  Concord
 -  Richmond
 -  Jackson
 -  Phoenix
Solution: Richmond
Which is the capital of Delaware ?
 -  Charleston
 -  Columbia
 -  Dover
 -  Baton Rouge
Solution: Dover
Which is the capital of Iowa ?
 -  Honolulu
 -  Indianapolis
 -  Des Moines
 -  Atlanta
Solution: Des Moines
Which is the capital of Illinois ?
 -  Springfield
 -  Augusta
 -  Santa Fe
 -  Phoenix
Solution: Springfield
Which is the capital of the Hawaii ?
 -  Honolulu
 -  Des Moines
 -  Juneau
 -  Albany
Solution: Honolulu
Which is the capital of Georgia ?
 -  Annapolis
 -  Atlanta
 -  Carson City
 -  Augusta
Solution: Atlanta
Which is the capital of Texas ?
 -  Helena
 -  Austin
 -  Cheyenne
 -  Little Rock
Solution: Austin
Which is the capital of Arkansas ?
 -  Little Rock
 -  Olympia
 -  Carson City
 -  Trenton
Solution: Little Rock
Which is the capital of Maine ?
 -  Tallahassee
 -  Augusta
 -  Harrisburg
 -  Albany
Solution: Augusta
Which is the capital of Florida ?
 -  Tallahassee
 -  Baton Rouge
 -  Charleston
 -  Pierre
Solution: Tallahassee
Which is the capital of Nevada ?
 -  Albany
 -  Carson City
 -  Concord
 -  Jefferson City
Solution: Carson City
Which is the capital of Minnesota ?
 -  Montgomery
 -  Saint Paul
 -  Charleston
 -  Denver
Solution: Saint Paul
Which is the capital of Louisiana ?
 -  Baton Rouge
 -  Columbus
 -  Bismarck
 -  Charleston
Solution: Baton Rouge
Which is the capital of Washington ?
 -  Hartford
 -  Tallahassee
 -  Denver
 -  Olympia
Solution: Olympia
Which is the capital of Alabama ?
 -  Lincoln
 -  Jackson
 -  Madison
 -  Montgomery
Solution: Montgomery
Which is the capital of Kansas ?
 -  Topeka
 -  Boston
 -  Salem
 -  Helena
Solution: Topeka
Which is the capital of Wisconsin ?
 -  Frankfort
 -  Jackson
 -  Boise
 -  Madison
Solution: Madison
Which is the capital of West Virginia ?
 -  Harrisburg
 -  Richmond
 -  Charleston
 -  Lincoln
Solution: Charleston
Which is the capital of Colorado ?
 -  Little Rock
 -  Saint Paul
 -  Montpelier
 -  Denver
Solution: Denver
Which is the capital of Massachusetts ?
 -  Augusta
 -  Little Rock
 -  Boston
 -  Richmond
Solution: Boston
Which is the capital of Montana ?
 -  Helena
 -  Madison
 -  Olympia
 -  Tallahassee
Solution: Helena




See ya soon

Comments

Popular posts from this blog

Widgets for Jupyter Notebook: a text input widget

Widgets for Jupyter notebook ¶ Let's import the module ipywidgets into the Jupyter Notebook from ipywidgets import widgets from ipywidgets import * from traitlets import * Now we import the display function from IPython ¶ let's attach a function to the event on_submit After we run this cell, we can go up and write something in the text widget and after you submit the text you wrote will be printed after the cell from IPython.display import display text = widgets . Text () display ( text ) def handle_submit ( sender ): print ( "Thank you for entering this text:" , text . value ) text . on_submit ( handle_submit ) Thank you for entering this text: Ciao

Image in Jupyter and PIL step by step

Hi, """ Hi, we will see a step by step tutorial about PIL and IPython.core.display modules to create images from other images and diplaying them in Jupyter notebook """ # What we will do # Create a card # 1. Take a pic of a heart # 2. Create an image blanck the size of a card 90*130 # 3. Paste the heart in the middle # 4. show the card """ As first step wi will simply display an image on the notebook. I will show two way to display the image with 'display' from IPhyton a. Using the open method of PIL.Image (named Img) b. Using the Image method from the IPython.core.display module """ # 1. Take the pic of a heart from IPython.core.display import Image , display from PIL import Image as Img heart = 'img/heart.png' display ( Image ( heart )) display ( Img . open ( heart )) # 2. Create an image blanck the size of a card 90*130 # 3. Paste the heart in the middle #...

Let's draw a circle with PIL in Python

Let's continue making our coding around PIL. Let's start with some basic drawing: a circle from PIL import Image , ImageDraw img = Image . new ( "RGB" ,( 60 , 60 ), 'white' ) dr = ImageDraw . Draw ( img ) dr . ellipse (( 0 , 0 , 60 , 60 ), 'yellow' ) img . show () this is the image produced *If you use jupyter notebook, just write img at the end to see the output.