This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Write a function sample that simulates N sets of coin flips and | |
#returns a list of the proportion of heads in each set of N flips | |
#It may help to use the flip and mean functions that you wrote before | |
import random | |
from math import sqrt | |
from plotting import * | |
def mean(data): | |
return float(sum(data))/len(data) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data=[1,2,5,10,-20,5,5,7, 7, 7, 7] | |
mode = [ data.count(data[i]) for i in range(len(data))] | |
print(data[mode.index(max(mode))]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
responses = {} | |
polling_active = True | |
while polling_active: | |
name = input("\nWhat is your name? ").upper() | |
response = input("Which mountain would you like to climbomeday? ").upper() | |
responses[name] = response | |
repeat = input("Would you like to let another person respond? (yes/no) ").lower() | |
if repeat == "no": | |
polling_active = False |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unconfirmed_users = ["peter", "tom", "mark", "brian", "agus", "tom", "travis"] | |
confirmed_users = [] | |
while unconfirmed_users: | |
current_user = unconfirmed_users.pop() | |
if current_user not in confirmed_users: | |
print("Verifying user: " + current_user.title()) | |
confirmed_users.append(current_user) | |
print("\nThe following users have been confirmed:") | |
for confirmed_user in confirmed_users: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while True: | |
print('Enter your age:') | |
age = input() | |
if age.isdecimal(): | |
break | |
print('Please enter a number for your age.') | |
while True: | |
print('Select a new password (letters and numbers only):') | |
password = input() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This program says hello and ask for my name. | |
print('Hello world!') | |
print('What is your name?') # ask for their name | |
myName = input() | |
print('It is good to meet you, ' + myName) | |
print('The length of your name is:') | |
print(len(myName)) | |
print('What is your age?') # ask for their age | |
myAge = input() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Data | |
revenue = [14574.49, 7606.46, 8611.41, 9175.41, 8058.65, 8105.44, 11496.28, 9766.09, 10305.32, 14379.96, 10713.97, 15433.50] | |
expenses = [12051.82, 5695.07, 12319.20, 12089.72, 8658.57, 840.20, 3285.73, 5821.12, 6976.93, 16618.61, 10054.37, 3803.96] | |
import numpy as np | |
profit_loss = [] | |
for i in range(0, len(revenue)): | |
profit_loss.append(revenue[i] - expenses[i]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def collatz(number): | |
if number % 2 == 0: | |
number = number // 2 | |
print(number) | |
while number != 1: | |
collatz(number) | |
break | |
elif number % 2 == 1: | |
number = 3*number + 1 | |
print(number) |