Professional Documents
Culture Documents
Solution 1.
def input_numbers():
a = int(input("Input a: "))
b = int(input("Input b: "))
c = int(input("Input c: "))
n = int(input("Input n: "))
return check_fermat(a, b, c, n)
input_numbers()
Solution 2.
def recursive_fib(n):
"""Recursive function to
print Fibonacci sequence"""
if n <= 1:
return n
else:
return(recursive_fib(n-1) + recursive_fib(n-2))
Solution 3.
import random
NUMBER_STUDENTS = 40
TRIALS = 1000
def has_duplicate(my_list):
i=0
while i < len(my_list):
if my_list.count(my_list[i]) > 1:
return True
elif i == (len(my_list) - 1):
return False
i += 1
def generate_random_birthdays():
return [random.randint(1, 365) for student in range(NUMBER_STUDENTS)]
def stats(TRIALS):
duplicate_count = 0
for i in range(TRIALS):
if has_duplicate(generate_random_birthdays()):
duplicate_count += 1
print "In %d classrooms with %d students, %.1f%% had students\
with duplicate birthdays." % (TRIALS, NUMBER_STUDENTS, (float(duplicate_count) /
TRIALS) * 100)
stats(TRIALS)
Solution 4.
Solution 4.
import numpy as np
import pandas as pd
from pandas import Series, DataFrame