## Guess Birthday

def main(): day = 0 # Day to be determined dates = [ [ [1, 3, 5, 7], [9, 11, 13, 15], [17,19, 21, 23], [25, 27, 29, 31] ], [ [2, 3, 6, 7], [10, 11, 14, 15], [18, 19, 22, 23], [26, 27, 30, 31] ], [ [4, 5, 6, 7], [12, 13, … Read moreGuess Birthday

## Finding the closest pair of points

#Compute the distance between towo points (x1, y1) and (x2, y2) def distance(x1, y1, x2, y2): return ((x2 – x1) * (x2 – x1) + (y2 – y1) * (y2 – y1)) ** 0.5 def nearestPoints(points): # p1 and p2 are the indexws in the points list p1, p2 = 0, 1 # Initial two … Read moreFinding the closest pair of points

def main(): # Students’ answer to the questions answers = [ [‘A’, ‘B’, ‘A’, ‘C’, ‘C’, ‘D’, ‘E’, ‘E’, ‘A’, ‘D’], [‘D’, ‘B’, ‘A’, ‘B’, ‘C’, ‘A’, ‘E’, ‘E’, ‘A’, ‘D’], [‘E’, ‘D’, ‘D’, ‘A’, ‘C’, ‘B’, ‘E’, ‘E’, ‘A’, ‘D’], [‘C’, ‘B’, ‘A’, ‘E’, ‘D’, ‘C’, ‘E’, ‘E’, ‘A’, ‘D’], [‘A’, ‘B’, ‘D’, ‘C’, … Read moreGrade An Exam (program that grades multiple-choice tests)

## Random Shuffling A matrix

import random matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] # Assume a list is given for row in range(len(matrix)): for column in range(len(matrix[row])): i = random.randint(0, len(matrix) – 1) j = random.randint(0, len(matrix[row]) – 1) # Swap matrix[row][column] with matrix [i][j] matrix[row][column], matrix[i][j] = matrix[i][j], matrix[row][column] for row in range(len(matrix)): for … Read moreRandom Shuffling A matrix

## Finding the sum of elements by column in a matrix

matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] # Assume a list is given for column in range(len(matrix[0])): total = 0 for row in range(len(matrix)): total += matrix[row][column] print(“Sum for column”, column, “is”, total)

## Finding the Row with largest Sum in a matrix

matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] maxRow = sum(matrix[0]) indexOfMaxRow = 0 for i in range(1, len(matrix)): if sum(matrix[i]) > maxRow: maxRow = sum(matrix[i]) indexOfMaxRow = i print(“Row”, indexOfMaxRow, “has the maximum sum of “, maxRow)

## Initialize Matrix with random values

import random matrix = [] # Create an empty list numberOfRows = eval(input(“Enter the number of rows: “)) numberOfColumns = eval(input(“Enter the number of columns: “)) for row in range(numberOfRows): matrix.append([]) #add an empty new row for column in range(numberOfColumns): matrix[row].append(random.randint(0, 99)) for row in matrix: for value in row: print(value, end=” “) print() # … Read moreInitialize Matrix with random values

## Initialize a Matrix and enter elements

matrix = [] # Create an empty list numberOfRows = eval(input(“Enter the number of rows: “)) numberOfColumns = eval(input(“Enter the number of columns: “)) for row in range(numberOfRows): matrix.append([]) #add an empty new row for column in range(numberOfColumns): value = eval(input(“Enter an element and press Enter: “)) matrix[row].append(value) print(matrix)

## Bouncing Balls

from tkinter import * # Import all definitions from tkinter from random import randint # Return a random color string in the form #RRGGBB def getRandomColor(): color = “#” for j in range(6): color += toHexChar(randint(0, 15)) # Add a random digit return color # Conver an integer to single hex digit in a character … Read moreBouncing Balls