#John Bible 11/28/21
#What I learned was how to use containment, operator precedence, and identity.
#What I had problems with was nothing I got through this without any issues.

lst_container = [4, 8, 5, 6]
x = 5
if (x in lst_container):
print(x, "is contained in list")
else:
print(x, "is NOT contained in list")
x = 10
if (x in lst_container):
print(x, "is contained in list")
else:
print(x, "is NOT contained in list")

```
5 is contained in list
10 is NOT contained in list
```

lst_container = [4, [7, 3], 'string element']
# 4 is an element in lst_container
x = 4
print(x, "contained in lst_container:", x in lst_container)
# 7 is an element of a list inside lst_container, but it is NOT an element of the lst_container
x = 7
print(x, "contained in lst_container:", x in lst_container)
# [7, 3] is an element of lst_container
x = [7, 3]
print(x, "contained in lst_container:", x in lst_container)

```
4 contained in lst_container: True
7 contained in lst_container: False
[7, 3] contained in lst_container: True
```

sentence = "This is a test sentence"
word1 = "test"
word2 = "something"
# testing if word1 is a substring of sentence
if (word1 in sentence):
print(word1, "is contained in:", sentence)
else:
print(word1, "is not contained in:", sentence)
# testing if word2 is a substring of sentence
if (word2 in sentence):
print(word2, "is contained in:", sentence)
else:
print(word2, "is not contained in:", sentence)
# another method to test if word2 is a substring of sentence
# using the not operator
if (word2 not in sentence):
print(word2, "is not contained in:", sentence)
else:
print(word2, "is contained in:", sentence)

```
test is contained in: This is a test sentence
something is not contained in: This is a test sentence
something is not contained in: This is a test sentence
```

# [ ] Write a program to prompt the user for an integer input between 0 and 100
# then print if the number is contained in `lst`
#This will prompt the user for an integer input between 0 and 100 and then print if the number is in lst
lst = [22, 89, 69, 78, 58, 22, 56, 13, 74, 8, 32, 58, 8, 63, 46, 79, 9, 38, 25, 96]
x=input("Enter a number between 0 and 100:")
x=int(x)
if (x in lst):
print(x, "is contained in list")
else:
print(x, "is NOT contained in list")

```
8 is contained in list
```

# [ ] The `records` list contains information about a company's employees
# each of the elements in `records` is a list containing the name and ID of an employee.
# Write a program to test if `applicant` is contained in `records` and display an appropriate message
#This will test if applicant is contained in records and display an appropriate message
# Records of names and IDs
records = [['Colette', 22347], ['Skye', 35803], ['Alton', 45825], ['Jin', 24213]]
applicant = ['Joana', 20294]
if (applicant in records):
print(applicant, "is in our records")
else:
print(applicant, "is NOT in our records")

```
['Joana', 20294] is NOT in our records
```

# [ ] Write a program to prompt the user for a letter (capital or small) then print if the letter is a vowel
# HINT: Use a string containing all the vowels and the `in` or `not in` operator
#This will prompt the user for a letter then print if the letter is a vowel
lst=["A","E","I","O","U","Y"]
x=input("Enter a letter")
x=x.upper()
if (x in lst):
print(x, "is a vowel")
else:
print(x, "is NOT a vowel")

```
A is a vowel
```

# x, y: equal, identical
x = 5
y = 5
print("x equal y ? ", x == y)
print("x is identical to y ?", x is y)

```
x equal y ? True
x is identical to y ? True
```

# x, y: not equal, not identical
x = 5
y = 6
print("x equal y ? ", x == y)
print("x is identical to y ?", x is y)

```
x equal y ? False
x is identical to y ? False
```

# x, y: equal, not identical
x = 5.6
y = 5.6
print("x equal y ? ", x == y)
print("x is identical to y ?", x is y)

```
x equal y ? True
x is identical to y ? False
```

# x, y: not equal, not identical
x = 5.6
y = 10.6
print("x equal y ? ", x == y)
print("x is identical to y ?", x is y)

```
x equal y ? False
x is identical to y ? False
```

# Different lists containing the same data
x = [4, 9, 8]
y = [4, 9, 8]
# x and y are equal, because they contain the same data
# x and y are NOT identical, because they are saved in different memory locations
print("x equal y ? ", x == y)
print("x is identical to y ?", x is y)
# Because they are not identical, changing x does not affect y
x[1] = 5
print()
print("After changing x[1]")
print("x =", x)
print("y =", y)
print("x equal y ? ", x == y)
print("x is identical to y ?", x is y)

```
x equal y ? True
x is identical to y ? False
After changing x[1]
x = [4, 5, 8]
y = [4, 9, 8]
x equal y ? False
x is identical to y ? False
```

# Identical list
x = [4, 9, 8]
y = x
# x and y are equal, because they contain the same data
# x and y are identical, because they are saved in the same memory location
print("x equal y ? ", x == y)
print("x is identical to y ?", x is y)
# Because they are identical, changing x also changes y
x[1] = 5
print()
print("After changing x[1]")
print("x =", x)
print("y =", y)
print("x equal y ? ", x == y)
print("x is identical to y ?", x is y)

```
x equal y ? True
x is identical to y ? True
After changing x[1]
x = [4, 5, 8]
y = [4, 5, 8]
x equal y ? True
x is identical to y ? True
```

# s1, s2: equal, not identical
s1 = 'whole milk'
s2 = 'whole milk'
print("s1 equal s2 ? ", s1 == s2)
print("s1 is identical to s2 ?", s1 is s2)
print("s1 is not identical to s2 ?", s1 is not s2)

```
s1 equal s2 ? True
s1 is identical to s2 ? False
s1 is not identical to s2 ? True
```

# s1, s2: equal, identical
s1 = 'whole milk'
s2 = s1
print("s1 equal s2 ? ", s1 == s2)
print("s1 is identical to s2 ?", s1 is s2)
print("s1 is not identical to s2 ?", s1 is not s2)

```
s1 equal s2 ? True
s1 is identical to s2 ? True
s1 is not identical to s2 ? False
```

# s1, s2: equal, identical (after interpreter optimization)
s1 = 'python'
s2 = 'python'
print("s1 equal s2 ? ", s1 == s2)
print("s1 is identical to s2 ?", s1 is s2)
print("s1 is not identical to s2 ?", s1 is not s2)

```
s1 equal s2 ? True
s1 is identical to s2 ? True
s1 is not identical to s2 ? False
```

# s1, s2: not equal, not identical
s1 = 'python'
s2 = 'java'
print("s1 equal s2 ? ", s1 == s2)
print("s1 is identical to s2 ?", s1 is s2)
print("s1 is not identical to s2 ?", s1 is not s2)

```
s1 equal s2 ? False
s1 is identical to s2 ? False
s1 is not identical to s2 ? True
```

# [ ] Write a program to:
# 1) Create a variable `e` that is equal but NOT identical to `s`
# 2) Test the equality and identity of `s` and `e` and print the results
# 3) Create a variable `i` that is equal and identical to `s`
# 4) Test the equality and identity of `s` and `i` and print the results
# 5) Test the equality and identity of `e` and `i` and print the results
#This will create variable e that is equal but not identical to s, test the equality and identity of s and e and print the results, create a variable i that is equal and identical to s, test the equality and identity of s and i and print the results, test the equality and identity of e and i and print the results
s = "Whole Wheat Bread"
#TODO
e= "Whole Wheat Bread"
print("e equal s ? ", e == s)
print("e is identical to s ?", e is s)
i=s
print("s equal i ? ", s == i)
print("s is identical to i ?", s is i)
print("e equal i ? ", e == i)
print("e is identical to i ?", e is i)

```
e equal s ? True
e is identical to s ? False
s equal i ? True
s is identical to i ? True
e equal i ? True
e is identical to i ? False
```

# [ ] Write a program to:
# 1) Create a variable `e` that is equal but NOT identical to `x`
# 2) Test the equality and identity of `x` and `e` and print the results
# 3) Create a variable `i` that is equal and identical to `x`
# 4) Test the equality and identity of `x` and `i` and print the results
# 5) Test the equality and identity of `e` and `i` and print the results
#This will create variable e which will be equal but not identical to x, test equality and indentity of x and e then printing the results, create i which will be equal and identical to x, test the equality and identity of x and i and print the results, test the equality and identity of e and i and print the results
x = [[-1, 2],[3, 4],[-5, 6]]
#TODO
e= [[-1, 2],[3, 4],[-5, 6]]
print("e equal x ? ", e == x)
print("e is identical to x ?", e is x)
i=x
print("x equal i ? ", x == i)
print("x is identical to i ?", x is i)
print("e equal i ? ", e == i)
print("e is identical to i ?", e is i)

```
e equal x ? True
e is identical to x ? False
x equal i ? True
x is identical to i ? True
e equal i ? True
e is identical to i ? False
```

# * has higher precedence
2 + 3 * 6

# To change precedence, we add ( )
(2 + 3) * 6

# Arithmetic and relational operations
3 * 2 < 10

# Exponentiation has a higher precedence
2**3 + 1 == 16

# Adding () changes the precedence of 3 + 1 and the exponentiation operator
2 ** (3 + 1) == 16

# Arithmetic, relational, and Boolean operators
2 ** (3 + 1) == 16 and 3 * 2 < 10

# Arithmetic, relational, Boolean, and containment operators
2 ** (3 + 1) != 16 or 3 * 2 in [5, 6, 3]

# Unexpected outcome!
6 < 10 != True

# Unexpected outcome!
6 < 10 != False

# Expected outcome after adding ()
(6 < 10) != True

# [ ] Correct the following expression so the answer is `True`
#This will make the answer True
(6 + 2 < 9) == True

# [ ] Correct the following expression so the answer is `True`
#This will make the answer True
3 ** (2 + 1) >= 3 * 8 + 1

# [ ] Correct the following expression so the answer is `True`
#This will make the answer True
(5 + 3) * 2 == 16

# [ ] Correct the following expression so the answer is `True`
#This will make the answer True
(4 > 3 and 5 + 6 > 7) == True