print('Hello World') a = 1 b = 2 print(a+b) #comments """last for many lines """ age = 50 if age >40: print('You are so old') else: print('kid') age = 30 if age >40: print('You are old') else: print('kid') print('This will be printed anyway') contributions = [1, 2, 4, 1, 4] print(sum(contributions)) for i in contributions: #print(i) print(f'Your contribution is: {i}. and payoff is {i*2}') #refer to a specific element print(contributions[0:3]) #the next lines are not included in the loop print(contributions[0]) print(contributions[0:2]) #gives me the first 2 elements print(contributions[-1]) #for the last element #create a list with only even numbers contri = [1, 3, 5, 33, 44, 6, 77, 89] new_list = [] for i in contri: if i % 2 == 0: #new_list.append(i) pass else: new_list.append(i) print(new_list) ##this is a better way to do the above new_list = [i for i in contri if i % 2 == 0] print(new_list) ##Power i=2 print(i**2) new_list = [i**2 for i in contri if i % 2 == 0] print(new_list) print(sum(new_list)) #Dictions ##left is the key and right is the value myinfo = {'name': 'Phillip', 'citizenship': 'Russian', 'work': 'HSE', 'list': [1, 2, 3, 3,], 'wife':{'name':'Anna'}, 'income': 5555} print(myinfo['name']) print(myinfo['work']) print(myinfo.keys()) for k in myinfo.keys(): print(k) for k in myinfo.values(): print(k) for k, v in myinfo.items(): print(f'Your {k} is {v}') ##can be used when a value is missing but you want a value instead print(myinfo.get('income', 999)) incomes = [100, 200, 300, 4099] def income_after_tax(income): tax_rate = 0.2 return round(income * (1-tax_rate)) for i in incomes: print(f'your income after tax is {income_after_tax(i)}') answer = 'No' possible_nos = ['Nope', 'No', 'Nehhh', 'Nein', 'Nvet'] if answer in possible_nos: print('NOOOOO') record = False else: record = True #different ways to create variable #mynewvariable = 1 #my_new_variable = 2 #player.payoff = 3 class Person: nation = 'Indian' name = 'Pooja' height = 163 weight = 60 def get_bmi(self): return round(self.height /100 ) / self.weight ** 2 #print(get_bmi) ph = Person() print(ph.nation) print(ph.get_bmi())