Skip to content

Instantly share code, notes, and snippets.

View magusafr's full-sized avatar

magusafr magusafr

View GitHub Profile
#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)
@magusafr
magusafr / gist:aed26790416b03ad1962d867ca44615a
Created September 2, 2018 06:46
mode first for the most occur of number
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))])
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
@magusafr
magusafr / gist:4c0f8a0334b9782b684dc3c840265452
Created June 29, 2018 14:47
check username in confirmed username
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:
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 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()
#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])
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)