# Pavan Kumpatla
# Dec 13, 2021
# I learned about in and not in, is and is not, and also about precendence
# No difficulties
lst_container = [4, 8, 5, 6]
# stores value
x = 5
# stores value
if (x in lst_container):
# if x is in lst_container
print(x, "is contained in list")
# print this
else:
# else
print(x, "is NOT contained in list")
# print this
x = 10
# stores value
if (x in lst_container):
# if x is in lst_container
print(x, "is contained in list")
# print this
else:
# else
print(x, "is NOT contained in list")
# print this
lst_container = [4, [7, 3], 'string element']
# stores value
# 4 is an element in lst_container
x = 4
# stores value
print(x, "contained in lst_container:", x in lst_container)
# prints, x is in lst_container (true or false)
# 7 is an element of a list inside lst_container, but it is NOT an element of the lst_container
x = 7
# stores value
print(x, "contained in lst_container:", x in lst_container)
# prints, x is in lst_container (true or false)
# [7, 3] is an element of lst_container
x = [7, 3]
# stores value
print(x, "contained in lst_container:", x in lst_container)
# prints, x is in lst_container (true or false)
sentence = "This is a test sentence"
# stores value
word1 = "test"
# stores value
word2 = "something"
# stores value
# testing if word1 is a substring of sentence
if (word1 in sentence):
# if word1 is in sentence
print(word1, "is contained in:", sentence)
# print this
else:
# else
print(word1, "is not contained in:", sentence)
# print this
# testing if word2 is a substring of sentence
if (word2 in sentence):
# if word2 is in sentence
print(word2, "is contained in:", sentence)
# print this
else:
# else
print(word2, "is not contained in:", sentence)
# print this
# another method to test if word2 is a substring of sentence
# using the not operator
if (word2 not in sentence):
# if word2 is not in sentence
print(word2, "is not contained in:", sentence)
# print this
else:
# else
print(word2, "is contained in:", sentence)
# print this
# [ ] Write a program to prompt the user for an integer input between 0 and 100
# then print if the number is contained in `lst`
lst = [22, 89, 69, 78, 58, 22, 56, 13, 74, 8, 32, 58, 8, 63, 46, 79, 9, 38, 25, 96]
# stores value
user = int(input("Enter Integer Input Between 0-100:- "))
# stores user input in int form
if user >= 0 and user <= 100:
# if user is greater than or equal to 0 and lesser than or equal to 100
if user in lst:
# if user in lst
print(user, "Is In The List")
# print this
else:
# else
print(user, "Is Not In The List")
# print this
else:
# else
print("Please Enter A Number Between 0-100!")
# print this
# [ ] 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
# Records of names and IDs
records = [['Colette', 22347], ['Skye', 35803], ['Alton', 45825], ['Jin', 24213]]
# stores list
applicant = ['Joana', 20294]
# stores list
if applicant in records:
# if applicant is in records
print(applicant, "Is In The Records!")
# print this
else:
# else
print(applicant, "Is Not In The Records!")
# print this
# [ ] 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
vowels = "AEIOUY"
# stores
user = input("Enter a Capital or Small Letter:- ").capitalize()
# stores user input in capitalized form
if user in vowels:
# if user in vowels
print(user, "is part of the Vowels!")
# print this
else:
# else
print(user, "is not part of the Vowels!")
# print this
# x, y: equal, identical
x = 5
# stores
y = 5
# stores
print("x equal y ? ", x == y)
# prints, x equals y (true or false)
print("x is identical to y ?", x is y)
# prints, x is y (true or false)
# x, y: not equal, not identical
x = 5
# stores
y = 6
# stores
print("x equal y ? ", x == y)
# prints, x equals y (true or false)
print("x is identical to y ?", x is y)
# prints, x is y (true or false)
# x, y: equal, not identical
x = 5.6
# stores
y = 5.6
# stores
print("x equal y ? ", x == y)
# prints, x equals y (true or false)
print("x is identical to y ?", x is y)
# prints, x is y (true or false)
# x, y: not equal, not identical
x = 5.6
# stores
y = 10.6
# stores
print("x equal y ? ", x == y)
# prints, x equals y (true or false)
print("x is identical to y ?", x is y)
# prints, x is y (true or false)
# Different lists containing the same data
x = [4, 9, 8]
# stores
y = [4, 9, 8]
# stores
# 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)
# prints, x equals y (true or false)
print("x is identical to y ?", x is y)
# prints, x is y (true or false)
# Because they are not identical, changing x does not affect y
x[1] = 5
# replaces index 1 of x with 5
print()
# prints nothing
print("After changing x[1]")
# prints
print("x =", x)
# prints
print("y =", y)
# prints
print("x equal y ? ", x == y)
# prints, x equals y (true or false)
print("x is identical to y ?", x is y)
# prints, x is y (true or false)
# Identical list
x = [4, 9, 8]
# stores
y = x
# y is x - x is now y
# 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)
# prints, x equals y (true or false)
print("x is identical to y ?", x is y)
# prints, x is y (true or false)
# Because they are identical, changing x also changes y
x[1] = 5
# replaces index 1 of x with 5
print()
# prints
print("After changing x[1]")
# prints
print("x =", x)
# prints
print("y =", y)
# prints
print("x equal y ? ", x == y)
# prints, x equals y (true or false)
print("x is identical to y ?", x is y)
# prints, x is y (true or false)
# s1, s2: equal, not identical
s1 = 'whole milk'
# stores
s2 = 'whole milk'
# stores
print("s1 equal s2 ? ", s1 == s2)
# prints, s1 equals s2 (true or false)
print("s1 is identical to s2 ?", s1 is s2)
# prints, s1 is s2 (true or false)
print("s1 is not identical to s2 ?", s1 is not s2)
# prints, s1 is not s2 (true or false)
# s1, s2: equal, identical
s1 = 'whole milk'
# stores
s2 = s1
# s1 is now s2
print("s1 equal s2 ? ", s1 == s2)
# prints, s1 equals s2 (true or false)
print("s1 is identical to s2 ?", s1 is s2)
# prints, s1 is s2 (true or false)
print("s1 is not identical to s2 ?", s1 is not s2)
# prints, s1 is not s2 (true or false)
# s1, s2: equal, identical (after interpreter optimization)
s1 = 'python'
# stores
s2 = 'python'
# stores
print("s1 equal s2 ? ", s1 == s2)
# prints, s1 equals s2 (true or false)
print("s1 is identical to s2 ?", s1 is s2)
# prints, s1 is s2 (true or false)
print("s1 is not identical to s2 ?", s1 is not s2)
# prints, s1 is not s2 (true or false)
# s1, s2: not equal, not identical
s1 = 'python'
# stores
s2 = 'java'
# stores
print("s1 equal s2 ? ", s1 == s2)
# prints, s1 equals s2 (true or false)
print("s1 is identical to s2 ?", s1 is s2)
# prints, s1 is s2 (true or false)
print("s1 is not identical to s2 ?", s1 is not s2)
# prints, s1 is not s2 (true or false)
# [ ] 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
s = "Whole Wheat Bread"
#TODO
e = "Whole Wheat Bread"
# stores
print("Check for \"s\" and \"e\"")
# prints
print("Equal Check:-", e == s)
# prints, e equals s
print("Indentical Check:-", e is s)
# prints, e is s (true or false)
i = s
# s is now i
print()
# prints nothing
print("Check for \"s\" and \"i\"")
# prints
print("Equal Check:-", s == i)
# prints, s equals i
print("Indentical Check:-", s is i)
# prints, s is i (true or false)
print()
# prints nothing
print("Check for \"e\" and \"i\"")
# prints
print("Equal Check:-", e == i)
# prints, e equals i
print("Indentical Check:-", e is i)
# prints, e is i (true or 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
x = [[-1, 2],[3, 4],[-5, 6]]
#TODO
e = [[-1, 2],[3, 4],[-5, 6]]
print("Check for \"x\" and \"e\"")
# prints
print("Equal Check:-", x == e)
# prints, x equals e
print("Indentical Check:-", x is e)
# prints, x is e (true or false)
i = x
# x is now i
print()
# prints nothing
print("Check for \"x\" and \"i\"")
# prints
print("Equal Check:-", x == i)
# prints, s equals i
print("Indentical Check:-", x is i)
# prints, s is i (true or false)
print()
# prints nothing
print("Check for \"e\" and \"i\"")
# prints
print("Equal Check:-", e == i)
# prints, e equals i
print("Indentical Check:-", e is i)
# prints, e is i (true or false)
# * has higher precedence
2 + 3 * 6
# multiplies, adds
# To change precedence, we add ( )
(2 + 3) * 6
# adds, multiplies
# Arithmetic and relational operations
3 * 2 < 10
# 2 is lesser than 10, multiplies
# Exponentiation has a higher precedence
2**3 + 1 == 16
# 2 to the power of 3 is 8 + 1 is 9 and that does not equal 16
# Adding () changes the precedence of 3 + 1 and the exponentiation operator
2 ** (3 + 1) == 16
# 3 + 1 is 4 so 2 to the power of 4 is 16 and 16 equals 16
# Arithmetic, relational, and Boolean operators
2 ** (3 + 1) == 16 and 3 * 2 < 10
# 3 + 1 is 4, 2 to the power of 4 is 16
# 2 is lesser than 10 and 3 * 2 is 6
# 16 equals 16
# 3 is lesser than 10
# True
# Arithmetic, relational, Boolean, and containment operators
2 ** (3 + 1) != 16 or 3 * 2 in [5, 6, 3]
# 2 is not [5, 6, 3]
# 3 + 1 is 4, 2 to the power of 4 is 16
# 16 does not equal to 16
# 3 * 2 = 6
# Unexpected outcome!
6 < 10 != True
# 6 is lesser than 10
# does not equal to True
# Unexpected outcome!
6 < 10 != False
# 6 is lesser than 10
# does not equal to False
# Expected outcome after adding ()
(6 < 10) != True
# 6 is lesser than 10, does not equal True
# [ ] Correct the following expression so the answer is `True`
(6 + 2 < 9) == True
# 6 + 2 = 8
# 8 < 9
# True
# [ ] Correct the following expression so the answer is `True`
3 ** (2 + 1) >= 3 * (8 + 1)
# 2 + 1 = 3
# 3 ^ 3 = 27
# 8 + 1 = 9
# 3 * 9 = 27
# True
# [ ] Correct the following expression so the answer is `True`
(5 + 3) * 2 == 16
# 5 + 3 = 8
# 8 * 2 = 16
# 16 = 16 -> True
# [ ] Correct the following expression so the answer is `True`
(4 > 3) and (5 + 6 > 7) == True
# 4 is greater than 3
# 5 + 6 = 11 -> Greater than 7
# True