Skip to content
1 hidden cell
Intermediate Python
Intermediate Python
Run the hidden code cell below to import the data used in this course.
1 hidden cell
Take Notes
Add notes about the concepts you've learned and code cells with code you want to keep.
Add your notes here
# Add your code snippets here
for index, row in brics.iterrows():
print(f"The population of {row['country']} is {row['population']} million!")
plt.hist(gapminder['life_exp'], bins = 5)
plt.xlabel('Year of life expectancy')
plt.ylabel('Quantity')
plt.title('Hisogram of life expectacy')
plt.show()
#for roll in range(10):
# dice1 = np.random.randint(1,10)
for i in range(10):
dice= [np.random.randint(1,6), np.random.randint(1,6)]
result = dice[0] + dice[1]
if (result == 7) or (result == 11):
print(' A win')
elif (result == 2) or (result == 3) or (result == 3):
print(' A loss')
else:
print('Roll Again')
Explore Datasets
Use the DataFrames imported in the first cell to explore the data and practice your skills!
- Create a loop that iterates through the
brics
DataFrame and prints "The population of {country} is {population} million!". - Create a histogram of the life expectancies for countries in Africa in the
gapminder
DataFrame. Make sure your plot has a title, axis labels, and has an appropriate number of bins. - Simulate 10 rolls of two six-sided dice. If the two dice add up to 7 or 11, print "A win!". If the two dice add up to 2, 3, or 12, print "A loss!". If the two dice add up to any other number, print "Roll again!".