All people:
Name: Ian, Age: 15
Name: Trevor, Age: 15
Name: Jack, Age: 32
Oldest Person: Jack
secretNumber = 15
print(secretNumber)
## secretNumber is an Integer
print(isinstance(secretNumber, int))
food = "Pizza"
print(food)
## food is a string
print(isinstance(food, str))
names = ["Nandan", "Arnav", "Torin", "Remy"]
print(names)
## names is an array, each element of names is a string
print(isinstance(names, list))
IamCool = True
print(IamCool)
## IamCool is a boolean
print(isinstance(IamCool, bool))
##Bonus Problem:
names_2 = {
"Nandan": "TeamMate1",
"Arnav": "TeamMate2",
"Torin": "TeamMate3",
"Remy": "TeamMate4",
}
print(names_2)
## name_2 is a dictionary, each key in the dictionary is a string, each value in the dictionary is also a string
print(isinstance(names_2, dict))
15
True
Pizza
True
['Nandan', 'Arnav', 'Torin', 'Remy']
True
True
True
{'Nandan': 'TeamMate1', 'Arnav': 'TeamMate2', 'Torin': 'TeamMate3', 'Remy': 'TeamMate4'}
True
import random
## usage of dictionary to store state abbreviations
stateAbr = {
"California": "CA",
"Nevada": "NV",
"Alaska": "AK",
"Hawaii": "HI",
"Arizona": "AZ"
}
# usage of integer to store score
score = 0
# usage of boolean
done = False
# using arrays here even though a dictionary would be better
states = ['California', 'Nevada', 'Alaska', 'Hawaii', 'Arizona']
capitals = ['Sacramento', 'Carson City', 'Juneau', 'Honolulu', 'Phoenix']
# prompt user with question
def promptUser():
state = random.randint(0, len(states) - 1)
a = input('What is the capital of ' + states[state])
return [a, state]
while not done:
guess = promptUser()
# check if answer is correct
if guess[0] == capitals[guess[1]]:
print('Correct! The capital of ' + stateAbr[states[guess[1]]] + " is " + capitals[guess[1]] + "!")
score += 1
else:
print('I am sorry, the capital of ' + stateAbr[states[guess[1]]] + " is " + capitals[guess[1]] + '.')
doneyet = input('Do you want to continue [y/n]: ')
# exit if user is finished
if doneyet == 'n':
done = True
# print score
print('Congratulations, your score is ' + str(score) + '!')
Correct! The capital of AZ is Phoenix!
Correct! The capital of CA is Sacramento!
I am sorry, the capital of NV is Carson City.
Correct! The capital of AZ is Phoenix!
Congratulations, your score is 3!