# Chapter 1 # Basic syntax examples ## arithmetic operators ## int x = 7 y = 3 z = x + y # 10 print(z) quantity = 4 price = 12.25 sub_total = quantity * price print(sub_total) tax = 7 # 7/100 total = sub_total + ( (tax / 100) * sub_total ) print(total) # 49.0 + ( ( .07/100 ) + 49.0 ) # string operators # concat or join fname = "Philip" lname = "Matusiak" fullname = fname + " " + lname print(fullname) # escapes for string course = "Philip's Python Class" print(course) # index of strings lastName = "Matusiak" # length of 8 chars range 0-7 letter = lastName[0] # get the first position of the list print(letter) print(lastName[0]) # slicing strings print(fullname) print(len(fullname)) # print the length of the var fullname 15 range 0-14 first3 = fullname[0:3] # [0] [1] [2] print(first3) last1 = fullname[-1] # [15] print(last1) lengthOfVar1 = len(fname) print(lengthOfVar1) group1Slice = fullname[0:lengthOfVar1] print(group1Slice) # input() function always as string fname = input("Enter your first name: ") print("Your entry was: " + fname) print( type(fname) ) # output the type of object age = 21 print( type(age) ) VIP_status = True print( type(VIP_status) ) # loops ## while loop valueX = input("Enter a control: ") x = int(valueX) # control var int while x < 20: # loop while condition x < 20 print(x) # expression sub operation of while x += 1 #increment by # for loop listOfNames = ["Philip", "Bob", "Joe", "Mary"] # len() 4 range 0-3 for fname in listOfNames: print(fname)