# This is a comment. # Use them to write short notes and descriptions in your code. c = 10 ''' Multi-line comments can be done like this, but not recommended. a = 10 b = 30 c = a + b ''' print(c) 1+2 # this won't be printed 3*4 # this will be printed print(1+2) print(3*4) 1+2; 3*4; flag = True # boolean variable clid = 370 # integer variable temp = 25.1 # float variable dept = 'EE' # string variable type(flag), type(clid), type(temp), type(dept) print(flag) print(clid) print(temp) print(dept) ( 2 * clid + 10 ) % 4 print(7/2) # true division print(7//2) # floor division temp_in_f = 1.8 * temp + 32 print(temp_in_f) 1j*1j a = 3+4j print (a.real) print (a.imag) print (a.conjugate()) print (abs(a)) num1 = temp_in_f print(num1) num1 += 10 # add and reassign print(num1) num1 -= 10 # subtract and reassign print(num1) num1 *= 2 # multiply and reassign print(num1) num1 /= 2 # divide and reassign print(num1) num2 = 77 print(num1 == num2) # should be False print(num1 != num2) # should be True print(num1 < num2) # should be False print(num1 >= num2) # should be True 5 > 3 > 4 5 > 3 < 4 == 1 + 3 t, f = True, False type(t) print(t and f) # Logical AND; print(t or f) # Logical OR; print(not t) # Logical NOT; print(t != f) # Logical XOR; print(t & f) # Logical AND; print(t | f) # Logical OR; print(not(t)) # Logical NOT; 2*dept dept + ' stands for Electronic Engineering' # classname = dept + clid # attempt to add a string and an integer classname = dept + repr(clid) print(classname) classid = f'The class ID for Software Lab is {dept}{clid}.' print(classid) classid.capitalize() classid.upper() classid.lower() classid.replace('EE', 'CS') a = [1,3,4,8,2,5,9,7,6] # this is a list print(a) type(a) len(a) a*2 a+a a a[0] # accessing the first element a[-1] # accessing the last element a[1:6:1] # accessing the elements from index 1 up to (but not including) index 6, with step size of 1 a[1:6:] a[1:6] a[1:6:2] # accessing the elements from index 1 up to (but not including) index 6, with steps specified by 2 a[::] a[::3] a[2::3] b = [1,3,'four',8] print(b) a = range(0,10,1) list(a) a = range(10) list(a) a = range(3,20) list(a) a = range(3,20,2) list(a) a = range(0,100,7) for i in a: i_squared = i*i print(i_squared) value = 9 # Controlling what happens next with if-elif-else if (value < 5): explanation = 'less than 5' value = 10 elif (value == 5): explanation = 'equal to 5' value = 15 else: explanation = 'greater than 5' value = 20 print(value) # what should this be? print(explanation) i = 0 while (i<100): print(i**2) i += 7 def sign(x): # this defines sign() function if x >= 0: return 1 else: return -1 for x in range(-5,5): print(x, sign(x), x*sign(x)) sqr = lambda x: x**2 # this defines sqr() function for x in range(-5,5): print(x,sqr(x))