You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In practical 3, task 4.1.2, setting everything up to run on one line can often be confusing and difficult to know what is happening. While students have just learned how to do this, it can seem relatively simple to know what goes where, but putting everything on one line teaches bad practices and can be especially hard to debug for students if an error is thrown (i.e. it could come from anywhere in the line). Suggest it is broken down into respective steps (just as we taught in the previous task) to make it clearer to students what they should be aiming for and best practices. See the potentially suggested code below:
import numpy as np
# Find the latitude of Manchester.
city = "Lerwick"
city_index = myData['Name'].index(city)
city_lat = myData["Latitude"][
city_index
]
print(f"{city}'s latitude is {city_lat}") # Notice how 'f-strings' work!
# # Find the easternmost city
max_long = np.max(myData["Longitude"])
max_long_position = myData["Longitude"].index( max_long)
city = myData['Name'][ max_long_position ]
print(f"The easternmost city is: {city}")
# # Print the location of Lerwick
city = "Lerwick"
print(f"The town of {city} can be found at " +
f"{abs(myData['Longitude'][myData['Name'].index(city)])}ºW, {myData['Latitude'][myData['Name'].index(city)]}ºN")
# # Find the mean population of the cities
# # using a handy package called numpy
mean = np.mean(myData['Population'])
print(f"The mean population is: {mean}")
The text was updated successfully, but these errors were encountered:
In practical 3, task 4.1.2, setting everything up to run on one line can often be confusing and difficult to know what is happening. While students have just learned how to do this, it can seem relatively simple to know what goes where, but putting everything on one line teaches bad practices and can be especially hard to debug for students if an error is thrown (i.e. it could come from anywhere in the line). Suggest it is broken down into respective steps (just as we taught in the previous task) to make it clearer to students what they should be aiming for and best practices. See the potentially suggested code below:
The text was updated successfully, but these errors were encountered: