{"cells":[{"cell_type":"markdown","metadata":{},"source":["# Exercise A: basic python"]},{"cell_type":"markdown","metadata":{},"source":["## A.1: Jupyter"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["a = 0\n","# Run this cell using 'Shift'+'Enter"]},{"cell_type":"markdown","metadata":{},"source":["b = 0 # this is a markdown cell, change it to code ('Esc' then 'y') and execute ('Ctrl'+'Enter') "]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["# Insert a cell below this one ('Esc' then 'b'), \n","# write a=1 and execute with 'Shift'+'Enter' (which will run and move to next) "]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["# Delete this cell ('Esc' then 'd' then 'd')"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["### Change this code cell to markdown ('Esc' then 'm') and execute with 'Shift'+'Enter'"]},{"cell_type":"markdown","metadata":{},"source":["## A.2 Variables"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["# Create variable called var_a with the value 2.0"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["# Now change the value of the variable var_a to \"my_string\""]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["# check the type of the variable var_a by using the type() function"]},{"cell_type":"markdown","metadata":{},"source":["## A.3 Lists"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["# Create a list called LA with three elements: 1.0, \"txt\" and 3 "]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["# Create a variable LB and set it equal to LA"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["# Change the first element of LB to \"b\""]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["# Print out the first element of LA. Did it change? Why? "]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["# Append a new element None to the list LA"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["# Print the list LB"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["# Create a new list LC, set it to the sum of LA and LB and print the result"]},{"cell_type":"markdown","metadata":{},"source":["## A.4 Tuples"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["# Create a tuple T with two elements \"1\" and 2.0"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["# Create two variables t1, t2 and set them to the first and second element of T"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["# Change the first element to 1.0. What happens? Why?"]},{"cell_type":"markdown","metadata":{},"source":["## A.5 Dictionaries"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["# Define an empty dictionary D with dict() "]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["# add a key-value pair using D[key] = value, with your initials and \n","# full name as key and value"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["# add a another key-value pair with initials and name of a colleague"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["# Print the value of the first item using square brackets []"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["# Define the same dictionary an alternative way using D={k1:v1, k2:v2}"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["# print all the keys using the keys() method on the D object, D.___()"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["# print all the items with with items()"]},{"cell_type":"markdown","metadata":{},"source":["## A.6 Control structures \n","\n","* [Python conditions](https://www.w3schools.com/python/python_conditions.asp)\n","* [Python for loop](https://www.w3schools.com/python/python_for_loops.asp)"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["v1 = 4.0\n","v2 = 5.0\n","# write the code that will print the statement \"great\" if v2 is greater than v1"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["# write the code that will do the same as above but also has an else statement \"not so great\""]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["L = [\"Hello\", \"World\"]\n","# write a for loop that loops through the elements of L and prints them"]}],"metadata":{"interpreter":{"hash":"fa576ebcd40e010bdc0ae86b06ce09151f3424f9e9aed6893ff04f39a9299d89"},"kernelspec":{"display_name":"Python 3.8.10 64-bit ('base': conda)","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.8.10"},"orig_nbformat":4},"nbformat":4,"nbformat_minor":2}