Procedure
We first examined and experimented with the entire page on the teacher repository to get a feel for the various hacks and how to implement them into our blog. After getting the hang of everything, we found that the mean calculator had the most potential to make something interesting out of. We were confused on the Union and repeatedly tried to get it to work, but in the end we found a way to bypass it but essentially do the same thing and learn the same data types. We then set off to customize our calculators, and I decided to try and bring in all the hacks together. I expanded the mean calculator to include standard deviation, which I thought was meaningful and fun to add, imported wikipedia to pull up an article about standard deviation (and other libraries to help the code work), and incorporated emojis in most output lines and added a quick paragraph about how to use these emojis. See the mean calculator below!
# formatting messages with emoji
# implemented with mean calculator
# exploring data with newspaper and wikipedia libraries
# implemented with mean calculator
# finding code on how the library we used was made
# implemented with mean calculator
# learning about data types while writing an algorithm for mean
import os
import emoji
os.system('pip install emoji')
os.system('pip install wikipedia')
print("")
os.system('echo "Your directory is as follows:"')
os.system('pwd')
print("")
# takes input from user and turns it into a list using .split()
raw = input("Type in numbers separated by a single space only and get the mean and standard deviation! Numbers: ")
datalist = raw.split()
# check to see if input is all numbers define each input in list as potential number
# code replaces "." with "" (blank) in each item to account for potential floats and checks if every potentialnumber isnumeric
# returns true if they are, returns false they are not
check = all(potentialnumber.replace(".","").isnumeric() for potentialnumber in datalist)
# if check is true, then list is all numbers and the code runs calculations
if check == True:
for x in range(len(datalist)):
datalist[x] = float(datalist[x])
# Calculations
import math
# mean
sumofdata = sum(datalist)
roundedsum = round(sumofdata,2)
lengthofdata = len(datalist)
mean = sumofdata / lengthofdata
roundedmean = round(mean,2)
# SD
sumofsquareddistancefrommean = 0
for datapoint in datalist:
squareddistancefrommean = (datapoint - mean)**2
sumofsquareddistancefrommean += squareddistancefrommean
if lengthofdata == 1:
SDsamplelength = lengthofdata
else:
SDsamplelength = lengthofdata - 1
variance = sumofsquareddistancefrommean / SDsamplelength
SD = math.sqrt(variance)
roundedSD = round(SD,2)
# Output
print("")
print("Your data " + emoji.emojize(":backhand_index_pointing_right:") + " " + raw + ".")
print("The sum of your data " + emoji.emojize(":backhand_index_pointing_right:") + " " + str(sumofdata) + ". The rounded sum of your data " + emoji.emojize(":backhand_index_pointing_right:") + " " + str(roundedsum) + ".")
print("The number of data values you entered " + emoji.emojize(":backhand_index_pointing_right:") + " " + str(lengthofdata))
print("The mean of your data " + emoji.emojize(":backhand_index_pointing_right:") + " " + str(mean) + ". The rounded mean of your data " + emoji.emojize(":backhand_index_pointing_right:") + " " + str(roundedmean) + ".")
print("The standard deviation of your data " + emoji.emojize(":backhand_index_pointing_right:") + " " + str(SD) + ". The rounded standard deviation of your data " + emoji.emojize(":backhand_index_pointing_right:") + " " + str(roundedSD) + ".")
# Explain SD
print("")
print("Wondering what does standard deviation mean? Look no further!")
# try using import os (next line) os.system('pip install wikipedia') to run linux command
import wikipedia
from IPython.display import display, Markdown
searches = ["standard deviation"]
for search in searches:
result = wikipedia.search(search)
# print(result)
summary = wikipedia.summary(result[0], auto_suggest=False) # auto-suggest changes deviation to devision, so turns it off
# print(search)
print(summary) # for console display
# display(Markdown(summary)) # for Jupyter display
# Explain emojis
print("")
print("Notice all the emojis used?" + emoji.emojize(":thinking_face:"))
print("This is how to use the emojis!" + emoji.emojize(":grinning_face_with_smiling_eyes:"))
print("First the emoji library needs to be imported using \"import emoji\" " + emoji.emojize(":writing_hand:"))
print("Then, whenever you want to use an emoji, you need to use \"emoji.emojize(\":emoji_here:\")\" " + emoji.emojize(":exploding_head:"))
print("That's it" + emoji.emojize(":thumbs_up:") + "! Now go" + emoji.emojize(":backhand_index_pointing_right:") + "have fun" + emoji.emojize(":partying_face:") + emoji.emojize(":party_popper:") + "with your" + emoji.emojize(":oncoming_fist:") + "emojis" + emoji.emojize(":double_exclamation_mark:"))
# if check is false, then list contains stuff that isn't numbers and the code doesn't run calculations
else:
print("You did not enter only numbers " + emoji.emojize(":frowning_face_with_open_mouth:") + ". Please rerun the code and only enter numbers!")
# experimenting
# import sys
# from typing import Union
# Number = Union[int, float] # define Number as integer or float
# Numbers = list[Number] # define Numbers as list of Number
# Scores = Union[Number, Numbers]
# Scores = input("Type in numbers separated by a single space only and get the mean! Numbers: ") #is this how to get input? i just copied from own code
# datalist2 = Scores.split()
# #ok i get what the mean and average functions are doing, but how do you get the list of numbers (Numbers) to begin with?
# def mean(scores: Scores, method: int = 1) -> float:
# def average1(scores):
# sum2 = 0
# len2 = 0
# for score in scores:
# if isinstance(score, Number):
# sum2 += score
# len2 += 1
# else:
# print(str(score) + "is not a number.")
# return sum2 / len2
# def average2(scores):
# return sum(scores) / len(scores)
# print(mean(datalist2)) #err idk if this is right tbh
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: emoji in /home/jasongao/.local/lib/python3.10/site-packages (2.8.0)
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: wikipedia in /home/jasongao/.local/lib/python3.10/site-packages (1.4.0)
Requirement already satisfied: beautifulsoup4 in /usr/lib/python3/dist-packages (from wikipedia) (4.10.0)
Requirement already satisfied: requests<3.0.0,>=2.0.0 in /home/jasongao/.local/lib/python3.10/site-packages (from wikipedia) (2.31.0)
Requirement already satisfied: charset-normalizer<4,>=2 in /home/jasongao/.local/lib/python3.10/site-packages (from requests<3.0.0,>=2.0.0->wikipedia) (3.2.0)
Requirement already satisfied: idna<4,>=2.5 in /home/jasongao/.local/lib/python3.10/site-packages (from requests<3.0.0,>=2.0.0->wikipedia) (3.4)
Requirement already satisfied: urllib3<3,>=1.21.1 in /home/jasongao/.local/lib/python3.10/site-packages (from requests<3.0.0,>=2.0.0->wikipedia) (2.0.4)
Requirement already satisfied: certifi>=2017.4.17 in /home/jasongao/.local/lib/python3.10/site-packages (from requests<3.0.0,>=2.0.0->wikipedia) (2023.7.22)
Your directory is as follows:
/home/jasongao/vscode/students/_notebooks
Type in numbers separated by a single space only and get the mean! Numbers: 5 7 143 6.9
Your data ๐ 5 7 143 6.9.
The sum of your data ๐ 161.9. The rounded sum of your data ๐ 161.9.
The number of data values you entered ๐ 4
The mean of your data ๐ 40.475. The rounded mean of your data ๐ 40.48.
The standard deviation of your data ๐ 68.35619333071925. The rounded standard deviation of your data ๐ 68.36.
Wondering what does standard deviation mean? Look no further!
['Standard deviation', 'Coefficient of variation', 'Geometric standard deviation', 'Standard deviation (disambiguation)', 'Unbiased estimation of standard deviation', 'Standard score', 'Standard deviation line', 'Standard error', 'Pooled variance', 'Weighted arithmetic mean']
In statistics, the standard deviation is a measure of the amount of variation or dispersion of a set of values. A low standard deviation indicates that the values tend to be close to the mean (also called the expected value) of the set, while a high standard deviation indicates that the values are spread out over a wider range.
Standard deviation may be abbreviated SD, and is most commonly represented in mathematical texts and equations by the lower case Greek letter ฯ (sigma), for the population standard deviation, or the Latin letter s, for the sample standard deviation.
The standard deviation of a random variable, sample, statistical population, data set, or probability distribution is the square root of its variance. It is algebraically simpler, though in practice less robust, than the average absolute deviation. A useful property of the standard deviation is that, unlike the variance, it is expressed in the same unit as the data.
The standard deviation of a population or sample and the standard error of a statistic (e.g., of the sample mean) are quite different, but related. The sample mean's standard error is the standard deviation of the set of means that would be found by drawing an infinite number of repeated samples from the population and computing a mean for each sample. The mean's standard error turns out to equal the population standard deviation divided by the square root of the sample size, and is estimated by using the sample standard deviation divided by the square root of the sample size. For example, a poll's standard error (what is reported as the margin of error of the poll), is the expected standard deviation of the estimated mean if the same poll were to be conducted multiple times. Thus, the standard error estimates the standard deviation of an estimate, which itself measures how much the estimate depends on the particular sample that was taken from the population.
In science, it is common to report both the standard deviation of the data (as a summary statistic) and the standard error of the estimate (as a measure of potential error in the findings). By convention, only effects more than two standard errors away from a null expectation are considered "statistically significant", a safeguard against spurious conclusion that is really due to random sampling error.
When only a sample of data from a population is available, the term standard deviation of the sample or sample standard deviation can refer to either the above-mentioned quantity as applied to those data, or to a modified quantity that is an unbiased estimate of the population standard deviation (the standard deviation of the entire population).
Notice all the emojis used?๐ค
This is how to use the emojis!๐
First the emoji library needs to be imported using "import emoji" โ๏ธ
Then, whenever you want to use an emoji, you need to use "emoji.emojize(":emoji_here:")" ๐คฏ
That's it๐! Now go๐have fun๐ฅณ๐with your๐emojisโผ๏ธ