<jupyter_start><jupyter_text>Data TypesTo follow along it is handy to refer to the associated assignment page whichhas the output printed out.  Integer CalculationsThe first examples deal with integer calculations.  Division will truncate integer calculations and the % operator will produce the remainder. The statement x=-2 is called an assignment statement.<jupyter_code>x=-2
y=4
z=3
print (x+y, x*y, z/x, z/y, z%x, z%y)<jupyter_output>2 -8 -1.5 0.75 -1 3<jupyter_text>Floating point calculations and conversionsWe repeat with floating point calculations using "float" which is a built-in Python function that converts integers to floating point numbers.Also shown is "int" which converts floating point numbers to integers. Notethat when an integer and floating point number are involved in the samecalculation, the result is a floating point number.<jupyter_code>x = float(x)
y = float(y)
z = float(z)
print (x, y, z)
print (z/x, z/y, int(z/y))

k=int((z/x)*(1))
print('Integer {}'.format(k))      # This produces an integer.
l=int((z/x)*(1.0))     # This produces a floating point number.
l<jupyter_output>-2.0 4.0 3.0
-1.5 0.75 0
Integer -1<jupyter_text>Order of Operations calculationsWhenever there is doubt about a variable's type, the interpreter can be used.For any variable such as x, enter type(x) in the interpreter and the type ofvariable will be displayed.  The order of operations can be remembered usingthe acronym PEMDAS.  Note the difference between * and **.<jupyter_code>print (1+2*5, (1+2)*5, (4-2)**0.5)
print  (y*x, y*(1/x), y**x)<jupyter_output>11 15 1.4142135623730951
-8.0 -2.0 0.0625<jupyter_text>Combinations of Functions and OperationsFunctions and operations can be combined.  Note the use of % and int(). The  absolute value function is abs().  Round() will round a number to a specificnumber of decimal places.  Round(12.345,2)= 12.35.<jupyter_code>m = int((4-2)**0.5)
print (m)
print (y*(1%x))             # Note that -2.0 does not divide 1 so 1%(-2.0)=-1.0. 
n = int(y*(1%x))
n<jupyter_output>1
-4.0<jupyter_text>StringsA string is a sequence of characters.  If the sequence involves numbers,they are treated as characters.  The built-in function len() tells us thelength of the string.  The first character in a string is indexed by thenumber zero.  A negative index can be used.  This starts the counting from end of the string.  All indexes are placed within brackets as shown below.Python is memoryless.  The variables x, y and z can be defined as stringseven though they were initially integers and then floating point numbers.<jupyter_code>x='aax'
y='bbb'
z='123'
print (x[0], x[2], z[-1], x*5, len(x*5))

print('\nExamples of concatenation and use of len() and indexing:')
print (x+y, (x+y+z*2), len(x+y+z*2), (x+y+z*2)[6], (x+y+z*2)[-6])<jupyter_output>a x 3 aaxaaxaaxaaxaax 15

Examples of concatenation and use of len() and indexing:
aaxbbb aaxbbb123123 12 1 1<jupyter_text>Quadratic Formula Section R.4 Example 4 LialPolynomials and other equations may be coded and Python used as a calculator.This is demonstrated using Example 4 of Section R.4 Lial.<jupyter_code>a=1.0
b=-4.0
c=-5.0
root_1=(-b+(b**2-4*a*c)**0.5)/(2*a)
root_2=(-b-(b**2-4*a*c)**0.5)/(2*a)
print ('Root_1=', root_1)   # %root_1 indicates a variable will be printed.
print ('Root_2=', root_2)   # %root_2 indicates root_2 is to be printed.

# A handy function is round().  It rounds to an specified number of decimal
# places.  For example round(3.14159,2)=3.14.  Check the output.

'3.14159 rounded to two decimal places is {}'.format(round(3.14159,2))<jupyter_output>Root_1= 5.0
Root_2= -1.0
{'fraction_non_alphanumeric': 0.1167174937621292, 'fraction_numerical': 0.05045744385916274, 'mean_word_length': 4.611197511664074, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '210717', 'license': 'MIT', 'n_tokens_mistral': 1318, 'n_tokens_neox': 1228, 'n_words': 468, 'path': 'Fall2019/MSDS400/pythonPractice/Module1/Data Types.ipynb', 'repo_name': 'kbridge14/regression_things', 'size': '3607'}