Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"ses2-PRE-

primitivetypes.ipynb","provenance":[],"collapsed_sections":
[],"authorship_tag":"ABX9TyNCs1yiQMPzL6UfjEf5xWU/"},"kernelspec":
{"name":"python3","display_name":"Python 3"},"language_info":
{"name":"python"}},"cells":[{"cell_type":"markdown","metadata":
{"id":"GPyzo4JFCwQJ"},"source":["# Primitive data types\n","\n","\n","The basic
building blocks of python are called **variables**. Variables are used to store
information under a given label or name. \n","\n","When naming variables, there
exist certain rules we should follow:\n","* Variable names cannot start with a
number\n","* Variable names cannot contain spaces. Use $\\_$ instead\n","* Avoid
using capital letters (best practice is lowercase)\n","\n"]},
{"cell_type":"markdown","metadata":{"id":"v36SiLL9r8yN"},"source":["\n","In Python
primitive data types are the following:\n","\n","* **Integers**. Numbers without a
fractional component\n","* **Float**. Numbers with a fractional component\n","*
**Strings**. They are sequences of characters. Strings are immutable. When using
strings, bracket operators cannot be used on the left side of an assignment with
the intention of changing that string.\n","* **Booleans**. They take one of two
possible values (_True_ and _False_), they represent the result of comparisons"]},
{"cell_type":"markdown","metadata":{"id":"Mn9AGx-SsD-p"},"source":["### Exercise 1\
n","\n","1. Create a integer variable with name ```a```\n","2. Check its type\n","\
n","\n"," "]},{"cell_type":"code","execution_count":null,"metadata":
{"id":"74CzxlJ7sEir"},"outputs":[],"source":["<FILL IN CODE>"]},
{"cell_type":"markdown","metadata":{"id":"s22xLyTjzeGj"},"source":["### Exercise 2\
n","\n","1. Create a variable called ```my_int``` that stores the value ```1``` in
integer form\n","2. Create a variable ```my_float``` that stores the value ```1```
in float form\n","3. Create a variable ```my_string``` that stores the value
```1``` in string form\n","4. Create a variable ```my_bool``` that stores the
boolean value ```True```\n","5. Can you observe any difference in the output?"]},
{"cell_type":"code","execution_count":null,"metadata":{"id":"55uyjZv6ze-
w"},"outputs":[],"source":["<FILL IN CODE>"]},{"cell_type":"markdown","metadata":
{"id":"eDrD3i7OL8zv"},"source":["### Exercise 3\n","\n","1. What is the value of 2
+ 3 * 4 + 5? \n","2. What if you want to first add two plus three, then multiply by
4 and add 5? Write the code\n","3. Compare the value 2 and the result of 1*(5.0 -
3.0), can you observe any difference?"]},
{"cell_type":"code","execution_count":null,"metadata":{"id":"HMGqZbd-
MNUA"},"outputs":[],"source":["<FILL IN CODE>"]},
{"cell_type":"code","execution_count":null,"metadata":
{"id":"VR9a_C4pRjOL"},"outputs":[],"source":["<FILL IN CODE>"]},
{"cell_type":"code","execution_count":null,"metadata":{"id":"z6ZKn0r-
RjON"},"outputs":[],"source":["<FILL IN CODE>"]},
{"cell_type":"markdown","metadata":{"id":"WHr2arD4MLTZ"},"source":["### Exercise 4\
n","\n","1. Create a variable ```my_var``` with the value ```\"find the last
character\"``` and check its length\n","2. Try getting the last character of this
string\n","3. Now try the code ```my_var[-1]```, what does it do?\n"]},
{"cell_type":"code","execution_count":null,"metadata":
{"id":"OwHMgXu6B6Bu"},"outputs":[],"source":["<FILL IN CODE>"]},
{"cell_type":"code","execution_count":null,"metadata":
{"id":"yovMZZk9RjOP"},"outputs":[],"source":["<FILL IN CODE>"]},
{"cell_type":"code","execution_count":null,"metadata":{"id":"-
eyh7HEWRjOQ"},"outputs":[],"source":["<FILL IN CODE>"]},
{"cell_type":"markdown","metadata":{"id":"IPDLo_wtznoh"},"source":["### Exercise 5\
n","\n","1. Create a variable ```my_var``` with the value ```\"My red car\"```\
n","2. Slice it to recover the word `car`\n","3. Use the built-in function
```split()``` and observe its output. Can you guess the output type?"]},
{"cell_type":"code","execution_count":null,"metadata":
{"id":"JulDYVD_zqla"},"outputs":[],"source":["<FILL IN CODE>"]},
{"cell_type":"code","execution_count":null,"metadata":
{"id":"dNB2awfQRjOS"},"outputs":[],"source":["<FILL IN CODE>"]},
{"cell_type":"code","execution_count":null,"metadata":
{"id":"RbjNK9hgRjOT"},"outputs":[],"source":["<FILL IN CODE>"]},
{"cell_type":"markdown","metadata":{"id":"-pvPzbcJxCWT"},"source":["### Exercise 6\
n","\n","1. Create a variable ```var_1``` with the value ```'Hello'```. Create
another variable ```var_2``` with the value ```'World'```.\n","2. Can you operate
with these two variable to obtain the result ```'Hello World'```? Write the
code."]},{"cell_type":"code","execution_count":null,"metadata":
{"id":"RpTjcRrtxORx"},"outputs":[],"source":["<FILL IN CODE>"]},
{"cell_type":"code","execution_count":null,"metadata":
{"id":"eFC6elL6RjOV"},"outputs":[],"source":["<FILL IN CODE>"]},
{"cell_type":"markdown","metadata":{"id":"0-eUhZlTxzLl"},"source":["### Exercise 7\
n","\n","1. Create a variable called ```pi``` and set it to the value 3.141593\
n","2. Convert this variable to an integer and check its value\n","3. Convert it
back to float and check its value once again"]},
{"cell_type":"code","execution_count":null,"metadata":
{"id":"Nv4x7zZAx7Nl"},"outputs":[],"source":["<FILL IN CODE>"]},
{"cell_type":"code","execution_count":null,"metadata":
{"id":"q2cnMU7MRjOW"},"outputs":[],"source":["<FILL IN CODE>"]},
{"cell_type":"markdown","metadata":{"id":"kHP0wDKPx74Z"},"source":["### Exercise 8\
n","\n","1. Create a variable called ```var``` and set it to the value
```'twelve'```\n","2. Check the type of this variable"]},
{"cell_type":"code","execution_count":null,"metadata":{"id":"Pb6YN-
snyG3b"},"outputs":[],"source":["<FILL IN CODE>"]},
{"cell_type":"markdown","metadata":{"id":"vJjYc2yf24c0"},"source":["### Exercise 9\
n","\n","1. Write the Python code `3.0 == 3` and execute the cell. What's the
meaning of the output?\n","2. Create a variable `my_True` that stores the boolean
value `True`and `my_False` that stores the boolean value `False`\n","3. Sum
`my_True` and `my_False` and observe the output\n","4. Multiply `my_True` and
`my_False` and observe the output"]},
{"cell_type":"code","execution_count":null,"metadata":
{"id":"D_RM0H_c241a"},"outputs":[],"source":["<FILL IN CODE>"]},
{"cell_type":"code","execution_count":null,"metadata":
{"id":"a2uD2CdoRjOZ"},"outputs":[],"source":["<FILL IN CODE>"]},
{"cell_type":"code","execution_count":null,"metadata":
{"id":"EI0ca78sRjOZ"},"outputs":[],"source":["<FILL IN CODE>"]},
{"cell_type":"code","execution_count":null,"metadata":
{"id":"MVSw4mewRjOZ"},"outputs":[],"source":["<FILL IN CODE>"]},
{"cell_type":"markdown","metadata":{"id":"ITen1o9h4cKv"},"source":["### Exercise
10\n","\n","1. Create a variable called ```name``` with the value ```\"un, united
nations\"```\n","2. Write the code to retrieve only the first part of this string,
the acronym, in capital letters, i.e. ```UN```\n"]},
{"cell_type":"code","execution_count":null,"metadata":
{"id":"RLdoLSm93OPd"},"outputs":[],"source":["<FILL IN CODE>"]},
{"cell_type":"markdown","source":["### Exercise 11\n","1. Create two variables
called `x` and `y`\n","2. Ask the user to input an integer value for each variable\
n","3. Swap the two variables using a temporary variable called `temp`\n","4. Show
the value of `x` and `y`"],"metadata":{"id":"IKR6-JomgC0C"}},
{"cell_type":"code","source":["<FILL IN CODE>"],"metadata":{"id":"Po7BxOgegh-
f"},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":["###
Exercise 12\n","1. Create two variables called `x` and `y`\n","2. Ask the user to
input an integer value for each variable\n","3. Swap the two variables without
using a temporary variable\n","4. Show the value of `x` and `y`"],"metadata":
{"id":"K74uGxAthG4a"}},{"cell_type":"code","source":["<FILL IN CODE>"],"metadata":
{"id":"Jhbzf-irhW1g"},"execution_count":null,"outputs":[]},
{"cell_type":"markdown","source":["### Exercise 13\n","1. Prompt the user the
following message \"Converting temperature in Celsius to Fahrenheit\"\n","2. Ask
the user to input the Celsius degree and assign it to variable `celsius_degree`.
Convert the user input to float.\n","3. Calculate the degree in Farenheit using the
formula: fahrenheit = (celsius *1.8) + 32.\n","4. Show the temperature in
Farenheit\n","5. Repeat the same ensuring the Celsius and Fahrenheit degrees of the
last message only have two decimals"],"metadata":{"id":"603W0IGZhmO5"}},
{"cell_type":"code","source":["<FILL IN CODE>"],"metadata":
{"id":"A9vkQ7w9iyOQ"},"execution_count":null,"outputs":[]}]}

You might also like