import tkinter from tkinter import Canvas # get graphics functions # draws the flag of Norway def NorwayFlag(): window = tkinter.Tk() # create a canvas (of size 440 X 320 px) c = Canvas(window, width=440, height=320) c.pack() # red background c.create_rectangle(0, 0, 440, 320, fill="red", outline="red") # white stripes over red background c.create_rectangle(120, 0, 200, 320, fill="white", outline="white") c.create_rectangle(0, 120, 440, 200, fill="white", outline="white") # blue stripes over white ones c.create_rectangle(140, 0, 180, 320, fill="blue", outline="blue") c.create_rectangle(0, 140, 440, 180, fill="blue", outline="blue") # ----------------------------------------- # returns the number of peak values in the given number list def peakCount(lst): count = 0 # initialize count to 0 # check each number other than the first and last ones for i in range(1, len(lst)-1): if lst[i] > lst[i-1] and lst[i] > lst[i+1]: # peek number check count = count + 1 return count # ----------------------------------------- # prints the sum of each row in the given matrix def rowSums(matrix): for row in range(len(matrix)): sum = 0 # initialize sum to 0 (whenever it starts a new row) # for each number of the current row add the number to the sum for col in range(len(matrix[row])): sum = sum + matrix[row][col] # after adding all numbers of the row print it as requested print("Sum of row ", row + 1, ": ", sum) # ----------------------------------------- # returns the sum of the digits of a given integer def digitSum(num): # base case: when the number is one digit then return it back if num < 10: return num else: return num%10 + digitSum(num//10) #recursive case