-
Notifications
You must be signed in to change notification settings - Fork 0
/
PythonMean.py
47 lines (31 loc) · 1.11 KB
/
PythonMean.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python
# coding: utf-8
# In[41]:
import pandas as pd
import statistics
name = input("What's your name? ")
filename = "notas" + name + "-" + subject + ".csv"
file = open(filename, "w")
marks = []
user_marks = 0.0
## subject_range = int(input("How many subjects you have? "))
def mean_calc():
global user_marks
while user_marks != 666:
user_marks = float(input("What is your mark? Type 666 if you have already typed all your notes\n \t"))
marks.append(user_marks)
# Deletes the exit number (666) which per default, gets appended into the array 'marks'
marks.pop()
## Ask the user for the subject where that mark came from
subject = input("In what subject? ")
## Calculate the mean
mean = statistics.mean(marks)
## Create the DataFrame
notes_df = pd.DataFrame([ [marks], [mean] ], columns = [subject], index = ["Marks", "Mean"])
## Prints the DataFrame and the global mean
print(notes_df)
print("The global mean is", round(mean, 2))
file.write(str(notes_df))
file.close()
## Calls the function
mean_calc()