Python Forum
How to write a dict code in python - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: How to write a dict code in python (/thread-41016.html)



How to write a dict code in python - ariellea88 - Oct-30-2023

Hello dear All!

I am a newcomer, could you please explain what is required to do first here?


1. Write a function process(text). This function should return a dictionary where:
a) The keys of the dictionary are the names of colleges.
b) The values of the dictionary are the number of students admitted to each college.
c) The parameter text comes from the text file mingdan.txt. Be sure to specify the correct file encoding when calling the read_text function.

2. Write a function sort_dict(adict, reverse). This function should return a list where:
a) Each element in the list is a tuple in the form (key, value).
b) The parameter adict is of type dictionary. The parameter reverse controls whether to sort by the reverse order of values.

Requirements:
a) Use functions from the py4202.py file, such as read_text and output.
b) Place the complete code in master.py. Place the relevant test code in master_test.py, where some code has already been written. Please complete it.
c) The code uses third-party libraries matplotlib and wordcloud. Please use the following commands to install the third-party libraries:
pip install matplotlib
pip install wordcloud
If using macOS, replace "pip" with "pip3" in the above commands.
\\


Thank you!


RE: How to write a dict code in python - deanhystad - Oct-30-2023

Do you have a question? What have you tried so far? This is not a forum that does your homework for you.


RE: How to write a dict code in python - ariellea88 - Oct-31-2023

(Oct-30-2023, 12:17 PM)deanhystad Wrote: Do you have a question? What have you tried so far? This is not a forum that does your homework for you.

Hello! Thank you for your reply!

Yes! The question is how do you use different fonts in your code?
This one is the one I am stuck with.

Thanky you!


RE: How to write a dict code in python - Gribouillis - Oct-31-2023

(Oct-31-2023, 07:45 AM)ariellea88 Wrote: Yes! The question is how do you use different fonts in your code?
If you want to know how to post code in the forum, this is explained in the BBcode help page.


RE: How to write a dict code in python - buran - Oct-31-2023

It looks, the attached file py4202.py are some helper functions you are supposed to use in your code. Please, post what have YOU tried to complete the assignment. We are glad to help, but we are not here to do your homework for you.
Please, post your code (in code tags) and ask specific questions. Don't forget to include the full traceback (in error tags) if you get one.
Check Homework and No Effort Questions