Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Practical 3 Task 4.1.2 broken down into respective parts #25

Open
PhilipDW183 opened this issue Oct 19, 2022 · 0 comments
Open

Practical 3 Task 4.1.2 broken down into respective parts #25

PhilipDW183 opened this issue Oct 19, 2022 · 0 comments

Comments

@PhilipDW183
Copy link

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}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant