diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..34d5adf Binary files /dev/null and b/.DS_Store differ diff --git a/.idea/misc.xml b/.idea/misc.xml index 665eda6..8e5c8e5 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 31ba842..0cd1f8a 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -15,8 +15,18 @@ + + + + + - + + + + + @@ -25,6 +35,13 @@ + + + @@ -40,6 +57,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + $USER_HOME$/.subversion @@ -93,7 +227,28 @@ @@ -115,30 +270,59 @@ - - + + + - - + + + + - - + + + + - - + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + @@ -151,17 +335,52 @@ - - + + + + - - + + + + + + + + + file://$PROJECT_DIR$/Submissions/Matteo_Murat/Prime_numbers.py + 4 + + + file://$PROJECT_DIR$/Part2-DataTypes/b_list.py + 39 + + + file://$PROJECT_DIR$/Submissions/Matteo_Murat/my_list.py + 8 + + + file://$PROJECT_DIR$/Part2-DataTypes/c_dictionaries.py + 29 + + + file://$PROJECT_DIR$/Part2-DataTypes/d_tuples.py + 24 + + + + \ No newline at end of file diff --git a/Part1-Basics/i_for_loops.py b/Part1-Basics/i_for_loops.py index b239684..2df2ed1 100644 --- a/Part1-Basics/i_for_loops.py +++ b/Part1-Basics/i_for_loops.py @@ -24,7 +24,9 @@ print('Lets print a series of numbers') -for i in range(10): +range_var = range (10) + +for i in range(3): print(i) print('................................') @@ -49,7 +51,7 @@ print('................................') print('You can also create some shapes: ') text = '' -character = '@' +character = '' for i in range(1, 10): text += character print(text) @@ -57,7 +59,7 @@ print('................................') print('Nested loops are quite useful. Here an example') for i in range(1, 10): - text = '' + text = '_' for j in range(0, i): text += str(i) @@ -65,7 +67,7 @@ # Now combined with conditionals -reference_number = 3 +reference_number = 9 text = ' can be divided into ' print('................................') print('This are numbers which can be divided into ' + str(reference_number)) @@ -77,3 +79,4 @@ # Try to print prime numbers smaller than 100 + diff --git a/Part2-DataTypes/b_list.py b/Part2-DataTypes/b_list.py index 3331d75..bb8f386 100644 --- a/Part2-DataTypes/b_list.py +++ b/Part2-DataTypes/b_list.py @@ -34,7 +34,7 @@ print(my_list, '\n') print("use len() to count the items in a list") -len_list = len(my_list) +len_list = len(my_list) #I can use this var to compare print(len_list, '\n') print("indexing or slicing in a list") diff --git a/Part3-ExternalSources/README.md b/Part3-ExternalSources/README.md new file mode 100644 index 0000000..a2a7caf --- /dev/null +++ b/Part3-ExternalSources/README.md @@ -0,0 +1,3 @@ +# External Sources + +In this part we learn how to create our own repository in github. In addition to that, we explore how to call different functions from external sources or libraries. \ No newline at end of file diff --git a/Part3-ExternalSources/a_functions.py b/Part3-ExternalSources/a_functions.py new file mode 100644 index 0000000..506a04c --- /dev/null +++ b/Part3-ExternalSources/a_functions.py @@ -0,0 +1,50 @@ +# encoding: utf-8 + +################################################## +# This script shows an example of a script using functions as a way to simplify programming. +# This is a common structure +# +################################################## +# +################################################## +# Author: Diego Pajarito +# Copyright: Copyright 2019, IAAC +# Credits: [Institute for Advanced Architecture of Catalonia - IAAC, Advanced Architecture group] +# License: Apache License Version 2.0 +# Version: 1.0.0 +# Maintainer: Diego Pajarito +# Email: diego.pajarito@iaac.net +# Status: development +################################################## + +# We don't need libraries for this script + + +################################################## +# We have a temporal section for defining functions +def say_hi(given_name): + print('Hi ', given_name) + + +def a_function(argument_1, argument_2): + print('I received this arguments') + print('Argument 1: ' + str(argument_1)) + print('Argument 2: ' + str(argument_2)) + # Functions are used to manage operations + + # sometimes they return values + answer = argument_1 ** argument_2 + return answer + + +################################################## +# and now we have the section for our source code +name = 'All students' +say_hi(name) + +var1 = 2 +var2 = 8 + +returned_value = a_function(var1, var2) + +print('Value: ', returned_value) \ No newline at end of file diff --git a/Part3-ExternalSources/b_return_values.py b/Part3-ExternalSources/b_return_values.py new file mode 100644 index 0000000..ceb2886 --- /dev/null +++ b/Part3-ExternalSources/b_return_values.py @@ -0,0 +1,86 @@ +# encoding: utf-8 + +################################################## +# This script shows an example of a script using functions as a way to simplify programming. +# This functions can also return more than one value +# +################################################## +# +################################################## +# Author: Diego Pajarito +# Copyright: Copyright 2019, IAAC +# Credits: [Institute for Advanced Architecture of Catalonia - IAAC, Advanced Architecture group] +# License: Apache License Version 2.0 +# Version: 1.0.0 +# Maintainer: Diego Pajarito +# Email: diego.pajarito@iaac.net +# Status: development +################################################## + +# We don't need libraries for this script + + +################################################## +# We have a temporal section for defining functions + +def get_proportions(values, names, label): + answer_template = '%s from %s is %f times %s from %s' + proportions = [] + proportions.append(round(values[0] / values[1], 1)) + proportions.append(round(values[0] / values[2], 1)) + proportions.append(round(values[1] / values[2], 1)) + + print(answer_template % (label, names[0], proportions[0], label, names[1])) + print(answer_template % (label, names[0], proportions[1], label, names[2])) + print(answer_template % (label, names[1], proportions[2], label, names[2])) + + + +def get_averages(values1, values2): + average1 = sum(values1) / len(values1) + average2 = sum(values2) / len(values2) + return average1, average2 + + +################################################## +# and now we have the section for our source code +cities = {'names': ['Barcelona', 'Lisbon', 'Amsterdam'], + 'population': [5474482, 2827514, 2431000], + 'unemployment_rate': [17.24, 7.4, 3.3], + 'gdp_billions': [173, 72, 154]} +text_template = 'Average population is: %f \n Average unemployment rate is: %f' + +val1, val2 = get_averages(cities['population'], cities['gdp_billions']) + +#print(text_template % (val1, val2)) + +# This function prints the city names and GDP values using a template. Check it out above +get_proportions(cities['gdp_billions'], cities['names'], 'GDP') + + +# Now we proceed to calculate the GDP per capita. First, we create an empty list and lists for population and GDP +per_capita = [] +gdp_billions = cities['gdp_billions'] +population = cities['population'] +# Ths for loop goes across cities +for i in range(len(cities['gdp_billions'])): + # Here we transform GDP units from billions to millions. 1b = 1000m + gdp_mill = cities['gdp_billions'][i] * 1000 + # Here we transform population to millions. 1m = pop / 1000000 + pop_mill = population[i] / 1000000 + gdp_percapita = gdp_mill / pop_mill + per_capita.append(gdp_percapita) + +# We print the list in which we appended all individual values +print(per_capita) + +# See this formula as an exmaple of GDP per capita estimation +#cities['gdp_percapita'] = ( cities['gdp_billions'] * 1000 ) / ( cities['population'] / 1000000) + + +####################### +# Side note, calling lists within lists. It works also for dictionaries. +my_list = [["a","b","c"],["d","e","f"]] + +# print first item of second list in my_list +print (my_list[1][0]) diff --git a/Part3-ExternalSources/c_calling_external_scripts.py b/Part3-ExternalSources/c_calling_external_scripts.py new file mode 100644 index 0000000..a1e691b --- /dev/null +++ b/Part3-ExternalSources/c_calling_external_scripts.py @@ -0,0 +1,26 @@ +# encoding: utf-8 + +################################################## +# This script shows an example of a script calling an third-party script that serves to simplify programming. +# It uses the -- import -- command to refer to the external script. +# These ways of using or structuring source code are very common when programming with python +# they serve to make code simpler and distribute individual parts of programs +# +################################################## +# +################################################## +# Author: Diego Pajarito +# Copyright: Copyright 2019, IAAC +# Credits: [Institute for Advanced Architecture of Catalonia - IAAC, Advanced Architecture group] +# License: Apache License Version 2.0 +# Version: 1.0.0 +# Maintainer: Diego Pajarito +# Email: diego.pajarito@iaac.net +# Status: development +################################################## + +# We need to call the library we named -- ourlib -- + +import ourlib.our_script + +ourlib.our_script.our_help() diff --git a/Part3-ExternalSources/ourlib/__init__.py b/Part3-ExternalSources/ourlib/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Part3-ExternalSources/ourlib/our_script.py b/Part3-ExternalSources/ourlib/our_script.py new file mode 100644 index 0000000..b063d98 --- /dev/null +++ b/Part3-ExternalSources/ourlib/our_script.py @@ -0,0 +1,34 @@ +# encoding: utf-8 + +################################################## +# This script shows an example of an external script that serves to simplify programming. +# First, it has a single functions that prints out a help text. +# These files are very common data sources when programming with python +# they serve to make code simpler and distribute individual parts of programs +# +################################################## +# +################################################## +# Author: Diego Pajarito +# Copyright: Copyright 2019, IAAC +# Credits: [Institute for Advanced Architecture of Catalonia - IAAC, Advanced Architecture group] +# License: Apache License Version 2.0 +# Version: 1.0.0 +# Maintainer: Diego Pajarito +# Email: diego.pajarito@iaac.net +# Status: development +################################################## + +# We do not need external libraries + +text = 'This is the help text. It is printed by an external library which simplifies the way you' \ + 'write code. This scirpt is inside a folder that has a python file -- __init__.py -- that ' \ + 'indicates this is a python library and allows other scripts to call it using the ' \ + '-- import -- command' + +print('our script was imported\n') + + +def our_help(): + print(text) + diff --git a/Submissions/.DS_Store b/Submissions/.DS_Store new file mode 100644 index 0000000..9d412e4 Binary files /dev/null and b/Submissions/.DS_Store differ diff --git a/Submissions/Matteo_Murat/Prime_numbers.py b/Submissions/Matteo_Murat/Prime_numbers.py new file mode 100644 index 0000000..aef3e92 --- /dev/null +++ b/Submissions/Matteo_Murat/Prime_numbers.py @@ -0,0 +1,11 @@ +#reference_number = 9 +text = ' is a prime number ' +print('................................') +#print('This are numbers which can be divided into ' + str(reference_number)) +for i in range(1, 100): + first = i / i + second = i/1 + # print('Residual value of dividing ' + str(i) + ' / ' + str(reference_number) + ' = ' + str(residual)) + if first == 1: + if second == i: + print(str(i) + text) #+ str(reference_number)) \ No newline at end of file diff --git a/Submissions/Matteo_Murat/Robotic_arm.py b/Submissions/Matteo_Murat/Robotic_arm.py new file mode 100644 index 0000000..0564751 --- /dev/null +++ b/Submissions/Matteo_Murat/Robotic_arm.py @@ -0,0 +1,42 @@ +# encoding: utf-8 + +################################################## +# Author: Matteo Murat +# Copyright: Copyright 2020, IAAC +# Credits: [Institute for Advanced Architecture of Catalonia - IAAC, Advanced Architecture group] +# License: Apache License Version 2.0 +# Version: 1.0.0 +# Maintainer: Matteo Murat +# Email: matteo.murat@students.iaac.net +# Status: development +################################################## + +# End of header section + +desidered_distance = 4 +distance_1 = 5 +distance_2 = 10 +current_distance = 2 #you choose the number + +print('the current distance is: ') +print(current_distance) + +if current_distance >= distance_2: + print('so the robotic arm will move faster') + print('move 3 forward') +elif current_distance > distance_1: + print('so the robotic arm will move at the same speed') + print('move 3 forward') +elif desidered_distance <= current_distance <= distance_1: + print('so the robotic arm will move slower') + if current_distance < 3: + distance_to_move = (current_distance-desidered_distance) * 0.5 + print('the distance to move is:' + distance_to_move) + print(distance_to_move) +elif current_distance <= desidered_distance: + print('so the robotic arm will stop') + + + + + diff --git a/Submissions/Matteo_Murat/my_city.py b/Submissions/Matteo_Murat/my_city.py new file mode 100644 index 0000000..1daae8c --- /dev/null +++ b/Submissions/Matteo_Murat/my_city.py @@ -0,0 +1,26 @@ +# encoding: utf-8 + +################################################## +# Author: Matteo Murat +# Copyright: Copyright 2020, IAAC +# Credits: [Institute for Advanced Architecture of Catalonia - IAAC, Advanced Architecture group] +# License: Apache License Version 2.0 +# Version: 1.0.0 +# Maintainer: Matteo Murat +# Email: matteo.murat@students.iaac.net +# Status: development +################################################## + +# End of header section + + +city_name = 'Rome' +city_area = 12685 +city_population = 2873000 +city_density = city_population/city_area + +print('Population Density') +print(city_density) + +# or you can write it in this way +print('Population Density:'+ str(city_density) + ' inhabitants per km2') \ No newline at end of file diff --git a/Submissions/Matteo_Murat/my_dict.py b/Submissions/Matteo_Murat/my_dict.py new file mode 100644 index 0000000..f07b40a --- /dev/null +++ b/Submissions/Matteo_Murat/my_dict.py @@ -0,0 +1,17 @@ +city = {'name':'Turin','population':6500000} + +city_population = {'Turin': 6500000, 'Lecce': 15000, 'Bologna':5500000, 'Oporto':3000000, 'Madrid':6000000, 'Barcelona':300000 } +print(city) + +cities = {'names': ['Turin', 'Lecce', 'Bologna','Oporto','Madrid', 'Barcelona'], 'population':[6500000, 15000, 5500000, 3000000, 6000000, 300000]} + + +names = ['Turin', 'Lecce', 'Bologna','Oporto','Madrid', 'Barcelona'] + +population = [6500000, 15000, 5500000, 3000000, 6000000, 300000,] + +cities = [names, population] +number = len (names) + +for i in range (number): + dict_cities[] \ No newline at end of file diff --git a/Submissions/Matteo_Murat/my_list.py b/Submissions/Matteo_Murat/my_list.py new file mode 100644 index 0000000..2366d82 --- /dev/null +++ b/Submissions/Matteo_Murat/my_list.py @@ -0,0 +1,28 @@ + + +names = ['Turin', 'Lecce', 'Bologna','Oporto','Madrid', 'Barcelona'] + +population = [6500000, 15000, 5500000, 3000000, 6000000, 300000,] + +cities = [names, population] + +number_of_cities = len(names) +print(number_of_cities) + +#----------------------------- +#for i in range (number_of_cities): #to have names of cities one under the other +# print (cities[i]) + +#if number_of_cities >= 3: +# print(cities) +#else: +# print(str('you have '), number_of_cities, str('cities')) +#---------------------------- + +print(cities) +print(cities[0][4]) + +print('the city of ', cities[0][0], 'has ', cities [1][0], 'inhabitants') + +for i in range(number_of_cities): + print(cities[0][i], 'has a population of', cities [1][i]) \ No newline at end of file