Computation Program With Report
Computation Program With Report
Ghinda Dionis
23024853
CS4051 Fundamentals of computing
Spring 2023-24
Introduction - 2
Description - 2
Testing - 3
Reflections - 4
Code + comments - 5
1
Introduction
This report is the final product of the “Introduction to Comptuing”
course. The main focus of the course was learning and introducing us
students to Python, a programming language that’s powerful and
somewhat beginner-friendly.
My final task was to build a Python program that is capable of taking
marks as user input and as a result transform this information into
statistical data. The main analitical functions where:
mode - the number that occurs the most times in a group of
numbers.
median - the middle value in a group of values; that is, half the
values are greater than the miedian number and half the values are
less than the median number.
mean - set of varialbes is their sum deivded by their number.
skewness - the measure that indicates the asymmetry of the data. A
positive skew means the presence of more high marks, while a
negaative skew means the frequenct of several small marks.
Description
get_student_marks is used to take a list of marks of the students as
input, the program ensures that the user has introduced at least 2 marks
find_mode is used to find the mode from the mark list. It will calculate
which number is repeated the most and then it will return that number.
If all the numbers have the same frequency it returns the result
2
together with a formatted message showing the mean to two decimal
points.
Calculating mean.
3
Calculating median.
Calculating mode.
Calculating skewness.
Reflections
This Python program was a great exercise for learning and practicing
different concepts that I have discovered this semester in the
“Fundamentals of Computing” module. I have understood how to
implement basic algorithms, I had to figure out ways to implement the
mode, mean, median, and skewness, using mathematics, logic, and the
4
Python programming language. Because this program needed so
many different functions I have learned to break tasks into smaller, more
manageable ones and organize them better. It was my first time creating
a project this big in Python so I had to research different methods, such
as dictionaries, lists, and definitions. Overall it was a great
experience and I feel I have learned a lot during this process.
print("Enter the marks of students one at a time, or multiple marks separated by commas.
Type 'done' to finish.") #print instruction for the user on how to input marks
while True: # start an infinite loop which will run until it is stopped
user_input = input("Enter mark(s) or 'done': ") #this user input line causes the user to
enter a mark or write done
print("Please enter at least two marks.") #if the user introduces less than 2 marks it
informs the user to add at least 2
continue #continues the loop until the required amount of marks has been
introduced
break #it breaks the loop if more than 2 marks have been introduced
if ',' in user_input: #if there are commas in the input the program divides the String by
commas
5
print("Invalid input detected. Please enter only numeric values separated by
commas.") #if it's not a valid number it will print an error message
try: #start the following block of code to test it, it is used here because converting a
String to a float might not work if the string isn't a valid number
except ValueError: #catches errors that could happen with try; it looks for the
ValueError which is an error when Python tries to convert a non-number into a number
print("Invalid input. Please enter a numeric value.") #this line will print an error
message if the user did not input a numeric value
frequency = {}#this is a dictionary called 'frequency' that takes into account how many
times each number appears in the list
for num in numbers:#this loop looks through each number in the list
modes = [num for num, count in frequency.items() if count == max_frequency] #this list
goes through the dictionary and collects all 'num' whose 'count' is equal to 'max_frequency'
return None, "No mode: All numbers occur the same amount of times." #if true it
returns None
return modes, f"More than one mode: {modes}" #if true returns list of modes
6
return modes[0], f"Mode: {modes[0]}" #if none of the above is true, return only 1 mode
n = len(numbers) # this method calculates the total amount of numbers in the list
mid = n // 2 # use floor division to round the number when calculating the mid
else: # if n is odd
mean = sum(numbers) / len(numbers) #mean is equal to the sum of the numbers divided
by the amount of elements in the list
mean = sum(numbers) / len(numbers) #mean is equal to the sum of the numbers divided
by the amount of elements in the list
7
def calculate_skewness(numbers): #define calculate_skewness function with numbers
return "Standard deviation is zero, skewness is undefined." #if its 0 it returns an error
message
print("1. Print the mean of the numbers") #print and choose the mean of the numbers
action
print("2. Print the median of the numbers") #print and choose the median of the numbers
action
print("3. Print the mode of the numbers") #print and choose the mode of the numbers
action
print("4. Print the standard deviation of the numbers") #print and choose the standard
deviation of the numbers action
print("5. Print the skewness of the numbers") #print and choose the skewness of the
numbers action
print("6. Enter a NEW set of numbers") #print and choose to enter a new set of numbers
action
8
print("7. Add MORE numbers") #print and choose to add more numbers action
print("8. Exit the application") #print and choose exit the application action
choice = input("Enter your choice: ") #allow user to make his choice based on the actions
above
9
marks = get_student_marks() # Start with a new set of marks
print("Exiting the application.") #print a message that says exiting the application
print("Invalid choice. Please enter a number from 1 to 9.") #the program informs the
user that they made an invalid choice
if __name__ == "__main__": #check if __name__ equals __main__ which means that the
script is executed as the main program
10