set_of_capitals = {'Washington, D.C.', 'Bogotá', 'Berlin'}
# Next line starts for statement
for capital in set_of_capitals:
print(capital, " is a capital of a country.")
# For statment ends
Run to view results
top_bands = {'The Beatles':{'John':["vocals", "guitars", "keyboards", 'harmonica', "bass",
"(1960–1969; died 1980)"],
'Paul':["vocals", 'bass', 'guitars', 'keyboards', 'drums', "(1960–1970)"],
'George':["guitars", 'vocals', 'sitar', 'keyboards', 'bass',
"(1960–1970; died 2001)"],
'Ringo':["drums", 'percussion', 'vocals', "(1962–1970)"]
},
'The Rolling Stones':{'Mick':["lead and backing vocals", 'harmonica', 'rhythm guitar',
'percussion', 'keyboards', 'bass guitar', "(1962–present)"],
'Keith':['rhythm and lead guitars', 'bass guitar', 'keyboards',
'percussion', 'backing and lead vocals', '(1962–present)'],
'Ronnie':['lead and rhythm guitars', 'bass guitar', 'backing vocals',
'(1975–present)']
}
}
Run to view results
for key in top_bands:
for key2 in top_bands[key]:
print(key2, "is a member of", key)
Run to view results
set_of_cities = {'Washington, D.C.', 'Bogotá', 'Berlin', 'Dallas'}
for city in set_of_cities:
if city in set_of_capitals:
print(city, "is a capital of a country")
else:
print(city, "is not a capital of a country")
Run to view results
n = 0
while n**2<=100:
n = n + 1
print(n)
Run to view results
artist_best_song = {
"Taylor Swift": "Fresh out the Slammer",
"Morgan Wallen": "Stand by me",
"Sabrina Carpenter": "Espresso",
"Gracie Abrams": "Close to you",
"Bailey Zimmerman": "Religiously",
"Zach Bryan": "Heavy Eyes",
"Rodney Atkins": "Caught up in the Country",
"Luke Combs": "Forever after all",
"Justin Bieber": "Ghost",
"Noah Kahan": "Forever"
}
for artist, song in artist_best_song.items():
print(f"{song} is the best song of {artist}.")
Run to view results
artist_best_song = {
"Taylor Swift": "Fresh out the Slammer",
"Morgan Wallen": "Stand by me",
"Sabrina Carpenter": "Espresso",
"Gracie Abrams": "Close to you",
"Bailey Zimmerman": "Religiously",
"Zach Bryan": "Heavy Eyes",
"Rodney Atkins": "Caught up in the Country",
"Luke Combs": "Forever after all",
"Justin Bieber": "Ghost",
"Noah Kahan": "Forever",
}
favorite_song_artist = {
"Fresh out the Slammer" : "Taylor Swift",
"Down Bad" : "Taylor Swift",
"Guilty as Sin" : "Taylor Swift",
"28" : "Zach Bryan",
"Cruel Summer" : "Taylor Swift",
"Heavy Eyes" : "Zach Bryan",
"Heading South" : "Zach Bryan",
"loml" : "Taylor Swift",
"close to you" : "Gracie Abrams",
"Who's afraid of little old me" : "Taylor Swift",
}
gender_artist = {
"Taylor Swift": "her",
"Morgan Wallen": "his",
"Sabrina Carpenter": "her",
"Gracie Abrams": "her",
"Bailey Zimmerman": "his",
"Zach Bryan": "his",
"Rodney Atkins": "his",
"Luke Combs": "his",
"Justin Bieber": "his",
"Noah Kahan": "his",
}
for artist, best_song in artist_best_song.items():
if best_song in favorite_song_artist and favorite_song_artist[best_song] == artist:
print(f"{best_song} is my favorite song of artist {artist}, and it is also {gender_artist[artist]}'s best song.")
else:
print(f"{best_song} is not one of my favorite songs of artist {artist}.")
Run to view results
top_bands = {
'The Beatles': {
'John': ["vocals", "guitars", "keyboards", 'harmonica', "bass", "(1960–1969; died 1980)"],
'Paul': ["vocals", 'bass', 'guitars', 'keyboards', 'drums', "(1960–1970)"],
'George': ["guitars", 'vocals', 'sitar', 'keyboards', 'bass', "(1960–1970; died 2001)"],
'Ringo': ["drums", 'percussion', 'vocals', "(1962–1970)"]
},
'The Rolling Stones': {
'Mick': ["lead and backing vocals", 'harmonica', 'rhythm guitar', 'percussion', 'keyboards', 'bass guitar', "(1962–present)"],
'Keith': ['rhythm and lead guitars', 'bass guitar', 'keyboards', 'percussion', 'backing and lead vocals', '(1962–present)'],
'Ronnie': ['lead and rhythm guitars', 'bass guitar', 'backing vocals', '(1975–present)']
}
}
for band, members in top_bands.items():
for member, details in members.items():
instruments = ', '.join(details[:-1]) # All elements except for the last one (which is the years)
years = details[-1] # The last element is the years they were in the band
death_year = None
if "died" in years:
death_year = years.split("died")[-1].strip().split(" ")[0]
alive_status = f"{member} passed away in {death_year}."
else:
alive_status = f"{member} is still alive."
print(f"{member} is a member of {band}.")
print(f"They play the following instruments: {instruments}.")
print(f"They belonged to the band from {years}.")
print(alive_status)
print()
Run to view results
max_value = 200
n = int(max_value ** 0.5)
while n % 2 != 0:
n -= 1
if n**2 < max_value:
print(f"The largest even integer n such that n^2 < 200 is {n}.")
else:
print("No even integer satisfies n^2 < 200.")
Run to view results