Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

251 changes: 235 additions & 16 deletions .idea/workspace.xml

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions Part1-Basics/i_for_loops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('................................')
Expand All @@ -49,23 +51,23 @@
print('................................')
print('You can also create some shapes: ')
text = ''
character = '@'
character = ''
for i in range(1, 10):
text += character
print(text)

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)

print(text)


# 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))
Expand All @@ -77,3 +79,4 @@


# Try to print prime numbers smaller than 100

2 changes: 1 addition & 1 deletion Part2-DataTypes/b_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 3 additions & 0 deletions Part3-ExternalSources/README.md
Original file line number Diff line number Diff line change
@@ -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.
50 changes: 50 additions & 0 deletions Part3-ExternalSources/a_functions.py
Original file line number Diff line number Diff line change
@@ -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)
86 changes: 86 additions & 0 deletions Part3-ExternalSources/b_return_values.py
Original file line number Diff line number Diff line change
@@ -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])
26 changes: 26 additions & 0 deletions Part3-ExternalSources/c_calling_external_scripts.py
Original file line number Diff line number Diff line change
@@ -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()
Empty file.
34 changes: 34 additions & 0 deletions Part3-ExternalSources/ourlib/our_script.py
Original file line number Diff line number Diff line change
@@ -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)

Binary file added Submissions/.DS_Store
Binary file not shown.
11 changes: 11 additions & 0 deletions Submissions/Matteo_Murat/Prime_numbers.py
Original file line number Diff line number Diff line change
@@ -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))
42 changes: 42 additions & 0 deletions Submissions/Matteo_Murat/Robotic_arm.py
Original file line number Diff line number Diff line change
@@ -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')





26 changes: 26 additions & 0 deletions Submissions/Matteo_Murat/my_city.py
Original file line number Diff line number Diff line change
@@ -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')
17 changes: 17 additions & 0 deletions Submissions/Matteo_Murat/my_dict.py
Original file line number Diff line number Diff line change
@@ -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[]
28 changes: 28 additions & 0 deletions Submissions/Matteo_Murat/my_list.py
Original file line number Diff line number Diff line change
@@ -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])