product_list, that takes as input a list of numbers, and returns a number that is the result of multiplying all those numbers together.
def product_list(p): result = 1 for i in p result = result * i return result
A greatest, that takes as input a list of positive numbers, and returns the greatest number in that list. If the input list is empty, the output should be 0.
def greatest(p): biggest = 0 for i in p: if i > biggeset: biggest = i return biggest
total_enrollment, that takes as an input a list of elements, where each element is a list containing three elements: a university name, the total number of students enrolled, and the annual tuition fees.
The procedure return two numbers, giving the total number of students enrolled at all of the universities in the list, and the total tuition fees (which is the sum of the number of students enrolled times the
# tuition fees for each university).
usa_univs = [ ['California Institute of Technology',2175,37704], ['Harvard',19627,39849], ['Massachusetts Institute of Technology',10566,40732], ['Princeton',7802,37000], ['Rice',5879,35551], ['Stanford',19535,40569], ['Yale',11701,40500] ] def total_enrollment(p): total_student = 0 total_tuition = 0 for i in p: total_sutudent = i + total_sudent total_tuition = i * i + total tuition return total_student, total_tuition
check_sudoku, that takes as input a square list of lists representing an n x n sudoku puzzle solution and returns the boolean True if the input is a valid sudoku square and returns the boolean False otherwise.
def check_sudoku(p): n = len(p) digit = 1 while digit <= n: i = 0 while i < n: row_count = 0 col_count = 0 j = 0 while j < 0 if p[i][j] == digit: row_count = row_count + 1 if p[j][i] = digit: col_count = col_count + 1 j = j + 1 if row_count != 1 or col_count != 1: return False i = i + 1 digit = digit + 1 return True
divided by number by bumbers showing dicimal
def list_mean(p): return float(sum(p)) / len(p)
better data structure indexing keyword, thinking data structure is the most important in computer science.
[[<keyword>,[<url>,<url>]] [<keyword>,[<url>,<url>]] ...]