#!/usr/bin/env python # coding: utf-8 # # Python Fundamentals: Introduction to Jupyter and Python # # SOLUTIONS # ## 🥊 Challenge 1: Printing # # Write your own `print` statement in the code cell below. Follow the syntax of the example above, and change the text in the quotation marks. # In[1]: # Write your own awesome print statement here! print('Hi, I\'m Tom') # ## 🥊 Challenge 2: Executing Cells Multiple Times # # Try using **Shift + Enter** to run the following cell three times. What is the output? Run the cell one more time. Is the output the same? # ANSWER: `a` keeps increasing. This is because each time we run the cell, the value in memory is updated and 1 is added. # ## 🥊 Challenge 3: Debugging Variable Names # # The following two blocks of code include variable names that cause an error. For each block of code, consider the following questions: # 1. Which rule is being broken? Can you find this information in the error message? # 2. What guidelines aren't being followed? # 3. How would you change the code? # In[2]: # use consistent style (e.g. snake case) avg_age = 30.332 another_variable = 28.801 print(avg_age - another_variable) # In[3]: # Variable names cannot include symbols like . country_1 = 'Zimbabwe' # Variable names are case-sensitive continent = 'Africa' print(country_1, 'is a country in', continent) # ## 🥊 Challenge 4: What The... # # What does the following error seem to tell you? Google the error and see if you can fix it! # In[4]: # SyntaxError: unmatched ')' # We need to remove the second closing parenthesis print('something went wrong') # ## 🥊 Challenge 5: Swapping Values # # Let's say we have two variables and we want to swap the values for each of them. # # Does the following method accomplish the goal? # # 💡 **Tip**: What is the value of first and last at the end of the cell? # In[5]: start = 1997 end = 1952 start = end end = start # Using a third temporary variable (you could call it `temp`), swap the first and last variables, so that `start = 1952` and `end = 1997`. # In[6]: start = 1997 end = 1952 # YOUR CODE HERE temp = start start = end end = temp print(start,end)