You are on page 1of 6

Supply chain management: Assignment 1_Nordstroms case study

September 19, 2016

Ashish Sanjay Menkudale


UIN: 656130575
Amenku2@uic.edu

Solution 1.

def check_fermat(a, b, c, n):


if n > 2 and (a**n + b**n == c**n):
print("Holy smokes, Fermat was wrong!")
else:
print("No, that doesnt work.")

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))

# asking input to the user


nth_term = int(input("How many terms? "))

# check if the number of terms is valid


if nth_term <= 0:
print("Plese enter a positive integer")
else:
print("Fibonacci sequence:")
for x in range(nth_term):
print(recursive_fib(x))

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.

# 4,a to read first 10 rows in CSV file


import os
import csv
import pandas as pd
data = pd.read_csv("titanic.csv", nrows=10)
print data

# 4.b to remove a particular column in CSV


import pandas as pd
df = pd.read_csv("titanic.csv")
keep_cols = ["PassengerId", "Survived", "Pclass", "Name" , "Sex", "SibSp", "Parch" ,
"Ticket" , "Fare" , "Cabin", "Embarked"]
new_df = df[keep_cols]
new_df.to_csv("removed.csv", index=False)

Solution 4.

import numpy as np
import pandas as pd
from pandas import Series, DataFrame

# 4.a to read first 10 rows


a= pd.read_csv ('Titanic.csv')
a.head(10)

#4.b to fill missing values of age


a.fillna (int(t["Age"].mean()), inplace = True)

# 4.c to sort data by Pclass and attribute Survived


a.sort_values(['Pclass','Survived'])

# 4.d to remove cabin column


a.drop ('Cabin', axis = 1, inplace = True)
print a

# 4.e to compare survived passangers within Pclass levels


a.query('Pclass == 1 and Survived == 1 ')
a.query('Pclass == 2 and Survived == 1 ')
a.query('Pclass == 3 and Survived == 1 ')

You might also like