the-magnificents / 04-02-2021-Carpentry-for-HGIS

A carpentry workshop focused on Digital Humanities audience that works with Geospatial Data.
Other
2 stars 3 forks source link

04-02-2021-Carpentry-for-HGIS/01_Day_1_Unix_Shell/excercises/B3_Exercise #55

Open utterances-bot opened 3 years ago

utterances-bot commented 3 years ago

Types and built-in functions — Python essentials for GIS learners

https://the-magnificents.github.io/04-02-2021-Carpentry-for-HGIS/01_Day_1_Unix_Shell/excercises/B3_Exercise.html

cforgaci commented 3 years ago

The get_gdp() function above throws an error, as the input values in get_gdp('1000000','500000','800000','100000','2000000') are not of the right type (string instead of integer or float).

manuGil commented 3 years ago

The + operator has different meanings when used with numeric values or when use with strings. When use with numbers (float, integers, etc) it means addition. When use with strings it means concatenation. In this case, use integers instead of strings. aka, remove the '' from the numbers. Ex. get_gdp(1000000, 500000, 800000, 100000, 2000000)

communisker commented 3 years ago

print("finished")

jurra commented 3 years ago

Indeed here you can see how the strings are not taken as numbers that is why is throwing, the error.

jurra commented 3 years ago

@cforgaci I wanted to actually have a code cell exemplifying how the wrong input outputs an error, but perhaps this makes things more complicated. Therefore I will put it back as integers. Thanks for your patience and the question.

cforgaci commented 3 years ago

@jurra, that was my response to the exercise. I realised that was the intention and the error helps to illustrate the importance of using the right types, so you could keep the wrong version for comparison.