Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made t13_mean_1 more compact #154

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions set_theory_find_unique_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,11 @@
appeared = {}

for i in range (len(arr)):
# Do something here
'''
Hint:
Use a dictionary to store the counts of the elements
Example: appeared[9] = 2
'''
if arr[i] in appeared:
appeared[arr[i]] += 1
else:
appeared[arr[i]] = 1

for i in appeared:
# Do something here
'''
Hint:
How do you check if something is unique?
What will appeared[i] equals to?
'''
if appeared[i] == 1:
print(i, end=" ")
15 changes: 6 additions & 9 deletions t13_mean1.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# Find the mean of n numbers

n = int(input("Enter number of numbers: "))
numbers = []
total = 0
for i in range(n):
numbers.append(float(input("Enter number: ")))
for number in numbers:
total = total + number
print(numbers)
print(total / n)
n = int(input("Enter an integer number of numbers: "))

numbers = [float(input("Enter number: ")) for i in range(n)]

print(f"List of numbers: {numbers}\nMean of the numbers: {sum(numbers)/ n}") # print the list of numbers and the mean