<jupyter_start><jupyter_text>Python Learning Notes Operators, Varibable Types, and Print 05/23/2020 Daily Objects1. Python-100-days: Day 22. Beginning Python: Read Chapter 13. Python Programming: Read Chapter 1 Progress1. Complete Day 2, notes attached2. Read Beginning Python Chapter 1  Notes Python-100-days: Day 21. Commands2. Variable types    1. Integer (`int`)        2. Float (`float`)        3. String (`str`)        4. Boolean (`bool`): logical True or False        5. Complex    3. Variable Naming    1. Cannot start with number        2. Case sensitive        3. Avoid function names        4. Meaningful<jupyter_code># Basic operators
# + - * /
# // floor division, round the result down to the nearest whole number
print(10 // 3) # floor division = 3
# % modulus
print(8 % 3) # modulus = 2
# ** exponentiation
# Assignment operators
a1 = 3
a1 += 3   # a1 = a1 + 3 = 3 + 3 = 6
a1 -= 5   # a1 = a1 - 5 = 6 - 5 = 1
a1 *= 100 # a1 = a1 * 100 = 1 * 100 = 100
a1 /= 2   # a1 = a1 / 2 = 100 / 2 = 50
a1 %= 3   # a1 = a1 % 3 = 50 % 3 = 2
a1 **= 3  # a1 = a1 ** 3 = 2^3 = 8
a1 //= 2  # a1 = a1 // 2 = 8 // 2 = 4
print(a1)
# Comparison operators, same as in R
# == != > < >= <= 
# Logical operators
# and, & in R
# or, | in R
# not, ! in R
# Identity operators
# is, is not
a = {"program":"A3SR"}
b = {"program":"A3SR"}
c = a
print(a is c)
print(a is b)
print(a == b)
# Membership operators
# in, not in
a = ["A3SR", "MS in DS"]
b = "MS in DS"
c = "Some other programs"
print(b in a)
print(c not in a)
# Bitwise operators
x = 0 # binary 0000
y = 1 # binary 0001
z = 5 # binary 0101
w = x # binary 0000

print(x & y) # Returns 0 because no pair of bits both contain 1
# x & y = 0000 & 0001 = 0000
print(y & z) # Returns 1 because 1 pair of bits both contain 1
# y & z = 0001 & 0101 = 0001

print(x | y) # Returns 1 because 1 pair of bits contain 1
# x | y = 0000 | 0001 = 0001
print(x | z) # Returns 5 (0101) because two pairs of bits contain 1
# x | z = 0000 | 0101 = 0101
print(x ^ y) # XOR
# x ^ y = 0000 ^ 0001 = 0001
print(~z) # NOT, use to get negative binary
# ~z = -(0101 + 0001) = -(0110) = -6
# Check variable types
a = 100
b = True
c = 'A3SR'
print(type(a)) # Note: must use print() to call a function. This is not required in R.
print(type(b))
print(type(c))
# Change variable types
print(str(a))
print(bool(c)) # If not zero or False, then True
print(bool(0)) # If zero, then False
# Print out results of basic arithmetic computation of two integers
a = int(input('a = '))
b = int(input('b = '))
# Use format placeholder
print('{} + {} = {}'.format(a, b, a + b))
# Exercise 1
# Fahrenheit to Celcius 
f = float(input('Fahrenheit: '))
c = (f - 32) / 1.8
print('{:.1f} F = {:.1f} C'.format(f, c)) # Round to 1 decimal
# Exercise 2
# Use radius to compute perimeter and area
radius = float(input('Radius = '))
pi = 3.141593
area = pi * radius**2
perimeter = 2 * pi * radius
print('Perimeter = {:.2f}'.format(perimeter))
print('Area = {:.2f}'.format(area))
# Exercise 3
# Determine leap year
year = int(input('Year = '))
is_leap = (year % 4 == 0 and year % 100 != 0) or year % 400 == 0
print(is_leap)<jupyter_output>Year = 200
False
{'fraction_non_alphanumeric': 0.14985682468978684, 'fraction_numerical': 0.08367801463569838, 'mean_word_length': 2.9949174078780176, 'pattern_counts': {'":': 2, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '579991', 'license': 'MIT', 'n_tokens_mistral': 1344, 'n_tokens_neox': 1126, 'n_words': 459, 'path': 'Daily Progress/Day 2 - Operators, Variable types, Print.ipynb', 'repo_name': 'tong-jin-nyu/Python-learning-notes', 'size': '3143'}