-
Notifications
You must be signed in to change notification settings - Fork 22
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
Homework5 #19
Open
Mozharovska
wants to merge
2
commits into
mate-academy:master
Choose a base branch
from
Mozharovska:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Homework5 #19
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#Write a function named sum_values that takes a dictionary named my_dictionary as a parameter. The function should return the sum of the values of the dictionary | ||
def sum_values (my_dictionary): | ||
sum = 0 | ||
for i in my_dictionary.values(): | ||
sum = sum + i | ||
return sum | ||
my_dictionary = {"milk":5, "eggs":2, "flour": 3} | ||
print(sum_values(my_dictionary)) | ||
my_dictionary = {10:1, 100:2, 1000:3} | ||
print (sum_values(my_dictionary)) | ||
|
||
#Create a function called sum_even_keys that takes a dictionary named my_dictionary, with all integer keys and values, as a parameter. This function should return the sum of the values of all even keys. | ||
def sum_even_keys (my_dictionary): | ||
count = 0 | ||
for key in my_dictionary.keys(): | ||
if key % 2 == 0: | ||
count += my_dictionary[key] | ||
return count | ||
my_dictionary = {1:5, 2:2, 3:3} | ||
print(sum_even_keys(my_dictionary)) | ||
my_dictionary = {10:1, 100:2, 1000:3} | ||
print(sum_even_keys(my_dictionary)) | ||
|
||
#Create a function named add_ten that takes a dictionary with integer values named my_dictionary as a parameter. The function should add 10 to every value in my_dictionary and return my_dictionary | ||
def add_ten(my_dictionary): | ||
for key in my_dictionary: | ||
my_dictionary[key] += 10 | ||
return my_dictionary | ||
my_dictionary = {1:5, 2:2, 3:3} | ||
print(add_ten(my_dictionary)) | ||
my_dictionary = {10:1, 100:2, 1000:3} | ||
print(add_ten(my_dictionary)) | ||
|
||
#Create a function named values_that_are_keys that takes a dictionary named my_dictionary as a parameter. This function should return a list of all values in the dictionary that are also keys. | ||
def values_that_are_keys (my_dictionary): | ||
list1 = [] | ||
for i in my_dictionary.values(): | ||
if i in my_dictionary.keys(): | ||
list1.append(i) | ||
return list1 | ||
my_dictionary = {1:100, 2:1, 3:4, 4:10} | ||
print(values_that_are_keys(my_dictionary)) | ||
my_dictionary = {"a":"apple", "b":"a", "c":100} | ||
print(values_that_are_keys(my_dictionary)) | ||
|
||
#Write a function named max_key that takes a dictionary named my_dictionary as a parameter. The function should return the key associated with the largest value in the dictionary. | ||
def max_key (my_dictionary) -> object: | ||
max_key = 0 | ||
for key,value in my_dictionary.items(): | ||
if value > my_dictionary.get(max_key,0): | ||
max_key = key | ||
return max_key | ||
my_dictionary = {1:100, 2:1, 3:4, 4:10} | ||
print(max_key(my_dictionary)) | ||
my_dictionary = {"a":100, "b":10, "c":1000} | ||
print(max_key(my_dictionary)) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
тут має бути перевірка того, парне чи не парне цей ключ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ісправіла)