<jupyter_start><jupyter_text>Variables: definition *Variables are placeholders to store data values to recover them later.*Consider the following analogy: you have a water source and you want to collect some water. If you don't have a placeholder (mug, bucket, bottle,...), you will not be able to collect it as the water will drain through your fingers. Variables need to have a name and this name can be anything you want as long as you follow some [rules](https://www.w3schools.com/python/gloss_python_variable_names.asp).<jupyter_code>x = 10
y = 20.5
z = 'hello'
print(x)
print(y)
print(z)<jupyter_output>hello<jupyter_text>Data Types  Python is a dynamically typed language. That means the interpreter infers the type of an object at runtime. Basic data types are:- **Integers**: stores positive or negative integer values. In Python, the integer type can be arbitrarily large. _(eg. 10, 3, -5)_- **Float**: stores decimal numbers. By default, Python interprets any number that includes a decimal point as a double precision floating point number. Like some other programming languages, in Python, there is not much difference between float and double except that float is in-built in Python, while double is imported from a library called `NumPy`. We will talk about the libraries in detail later. _(eg. 20.2, 100.2403, -5.50)_- **String**: stores a group of characters encapsulated in a single quote or double quotes _(eg. "hello", "Ironhack", "Teacher")_- **Boolean**: stores either a TRUE or FALSE To check our data types we will use the function `type()` (in Python, any name which is followed by opening and closing parentheses is a function) **Integer**<jupyter_code>x = 10 
print(x) 
type(x)<jupyter_output>10<jupyter_text>As you can see from the example above, `print` and `type` are followed by `()` and therefore they are functions. They take an argument and the return another value.  **Float**<jupyter_code>y = 20.5
print(y) 
type(y)<jupyter_output>20.5<jupyter_text>**String**  String can  be encapsulated in single quotes or double quotes.<jupyter_code>z = "hello" 
print(z) 
type(z)
x = 'hello there' 
print(x) 
type(x)<jupyter_output>hello there<jupyter_text>**Note:** As you can see from the examples above, you can define a string using double `" "` or single quotes`' '`. You may wonder when you should use double quotes and single quotes. The short answer is that depends on your string. If your string contains single quotes like `I couldn't make it` then, you must use double quotes. Otherwise, you are safe using single quotes. **Note:** in the previous two cases, the length of the string was small (they were single-line strings).   What if we want a string that is more than one line long (multiple line string).  In such cases, we use three single quotes. And every new line is represented by a '/n' character in the output.<jupyter_code># Multiple line string
x = '''Float - stores decimal numbers. By default, Python interprets any number that includes a decimal point as a double precision floating point number. Like some other programming languages, in Python there is not much difference between float and double except that float is in-built in Python, while double is imported from a library called NumPy.
We will talk about the libraries in detail later.
Hello
There!'''
print(x)
type(x)<jupyter_output>Float - stores decimal numbers. By default, python interprets any number that includes a decimal point as a double precision floating point number. Like some other programming languages, in python there is not much difference between float and double except that float is in built in python while double is imported from a library called numpy.
We will talk about the libraries in detail later.
Hello
There!<jupyter_text>**Boolean**<jupyter_code>x = True # this is higlighted in green because it is a key word
print(x) 
type(x)
x = False
print(x) 
type(x)
x = "True" # In this case it is a string because we encapsulated in double quotes 
print(x)
type(x)<jupyter_output>True<jupyter_text>Excercise: Data Types  **1. For the following variables, use Python to check the data type of the variables.**<jupyter_code>x1 = 1.1

x2 = "Ironhack"

x3 = "1.1"

x4 = True 

x5 = "True"

x6 = -1<jupyter_output><empty_output><jupyter_text>**2. What is the difference between `x1` and `x3`?**<jupyter_code>x3 is in qouations making it a string<jupyter_output><empty_output><jupyter_text>**3.Substract `x3` from `x1`**<jupyter_code>x3-x1<jupyter_output><empty_output><jupyter_text>**4. What is the difference between `x4` and `x5`?** 5 is in qoutations making it a string  **5.Substract `x4` from `x5`**  Operators Operators are special symbols in Python that are used to perform certain operations such as mathematical operations, logical operations, and comparison operations. The value or the variables that the operator works on are called Operands. We will look at some of the more common operators that we use in Python.<jupyter_code># We will define two variables here and use operators on them
x = 10
y = 5<jupyter_output><empty_output><jupyter_text>Arithmetic operators  These are used to perform mathematical operations as shown below: Here on the left hand side we have the operator and on the right we can see how they can be used with variables- `+` - Addition (x + y)- `-`	- Subtraction (x - y)- `*`	- Multiplication (x * y)- `/` - Division (x / y)- `%` - Modulus (x % y)- `**` - Exponentiation (x ** y)- `//` - Floor division (x // y)<jupyter_code># You can try and test these operators as shown below 
x+y
x-y
x*y
x/y
x%y # Gives the remainder
x**y # 'y' times multiplication of 'x'
x // y # Rounds off the result to the lower interger value on the number line<jupyter_output><empty_output><jupyter_text>Python also has a `math` library that you can use to perform some more complex mathematical operations.Libraries in python contain some additional pre-defined functions that the user can directly.We will talk about libraries in more detail later.<jupyter_code>Here we will show how to use [math library](https://docs.python.org/3/library/math.html) for some operations that we have looked at before .
import math # This is the way to have access to all the functions included in the `math` library
math.floor(2.9) # This is the same as 'floor division' operator that we used earlier 
# This is the same as 'Exponentiation' operator that we used earlier. 
# In this case, the function takes two arguments separated by ','. The first one is the base, 
# and the second is the power. In the example, below we're computing: 2**3
math.pow(2,3) 
math.sqrt(9) #This returns the square root<jupyter_output><empty_output><jupyter_text>Assignment Operators These are used to assign values to variables. We have already seen it before when we talked about 'Variables' and 'Data Types'<jupyter_code>x = 10
print(x)<jupyter_output>10<jupyter_text>Some special assignment operators assign the value and perform a simple mathematical operation at the same time. They are shown below:<jupyter_code>x += 3  is equivalent to x = x + 3<jupyter_output><empty_output><jupyter_text>x = 10x+=3print(x) x = 10x-=3print(x) x = 10x*=3print(x) x = 10x/=3print(x) x = 10x%=3print(x)<jupyter_code>### Comparison Operators
These are to make a comparison between two variables. They return a boolean value, either True or False.
Returns `True` if the condition is met, otherwise returns a `False`.<jupyter_output><empty_output><jupyter_text>==  Equal   x == y !=  Not equal  x != y >   Greater than  x > y <   Less than  x < y >=  Greater than or equal to  x >= y<=  Less than or equal to  x <= y<jupyter_code>x = 10  # Initialize variable `x` with a value 10
y = 5   # Initialize variable `y` with a value 5
x == y
x != y
x > y
x >= y
x<y
x <= y<jupyter_output><empty_output><jupyter_text>Logical Operators These operators are used to combine two or more comparison operations.  It returns True if all the conditions are met.  Returns a False if any one of the multiple conditions is not met.<jupyter_code>x = 10 # First we will initialize variable `x` with a value 10.<jupyter_output><empty_output><jupyter_text>**and**<jupyter_code>Returns True if both statements are true   
x < 5 and x < 10<jupyter_output><empty_output><jupyter_text>x < 5 and x < 10  x > 5 and x < 20<jupyter_code>**or**<jupyter_output><empty_output><jupyter_text>Returns True if one of the statements is true     x < 5 or x < 4<jupyter_code>x < 5 or x > 12
x == 10 or x > 12<jupyter_output><empty_output><jupyter_text>**not**<jupyter_code>Reverse the result, returns False if the result is true  
not(x < 5 and x < 10)<jupyter_output><empty_output><jupyter_text>not(x  12) not(x == 10 or x > 12)<jupyter_code>## More Resources:
https://www.programiz.com/python-programming/operators
https://www.tutorialspoint.com/python/python_basic_operators.htm
# Exercise Operators











**1. In this problem we will show you how to take a user input. Use the code and then answer the questions 
that follow:**<jupyter_output><empty_output><jupyter_text>x1 = input("Please enter an integer number: ")x2 = input("Please enter another integer number")Print the values of the two variables?What is the data type of `x1` and `x2`?As you would notice, data type of `x1` and `x2` is string. Even though we entered integers, the input functionconverts them into string by default. Now we do some data type conversion from string to integersx1 = int(x1)   This converts string into integer and re-initializes `x1`x2 = int(x2)   This converts string into integer and re-initializes `x2`Print the values of the two variables?What is the data type of `x1` and `x2`?Now perform simple comparisons between `x1` and `x2`    Check if the two variables are equal ?        Check if `x1` is greater than `x2`?        Check if `x2` is greater than `x1`?        Check if `x1` is not equal to `x2`?    Store the difference between the two varibles `x1` and `x2` in another variable `x3` (subtract the smaller number from the larger number)Increment the smaller of the two variables (`x1` and `x2`) with the difference. Again check if `x1` and `x2`are equal or not?<jupyter_code>**2. In the lesson we talked about 'math' library in python. [Here](https://docs.python.org/3/library/math.html) is a link to the documenation of this library. 
Go through the documentation and try any three more functions on a numerical variable that were not described 
in the lesson.**

## Additional Material<jupyter_output><empty_output><jupyter_text>The students will not be tested on these in the pre-work assessment!!<jupyter_code># We will talk about these later in the bootcamp. The definitions are below for your reference.
x = 10
y = 5<jupyter_output><empty_output><jupyter_text>**Identity Operator** **is** Returns `True` if both variables are the same object.The `x` is the `y`.<jupyter_code>x is y<jupyter_output><empty_output><jupyter_text>**is not** Returns `True` if both variables are not the same object.`x` is not `y`.<jupyter_code>x is not y<jupyter_output><empty_output><jupyter_text>**Membership Operator**<jupyter_code>a = 'I'
b = 'Ironhack'<jupyter_output><empty_output><jupyter_text>**in** Returns `True` if a sequence with the specified value is present in the object.`x` in `y`.<jupyter_code>a in b<jupyter_output><empty_output><jupyter_text>**not in** Returns `True` if a sequence with the specified value is not present in the object.`x` not in `y`.<jupyter_code>a not in b<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup