Looking for online/book Problems about the Python Classes

  • Context: Python 
  • Thread starter Thread starter Arman777
  • Start date Start date
  • Tags Tags
    Classes Python
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
5 replies · 2K views
Arman777
Insights Author
Gold Member
Messages
2,163
Reaction score
191
I started to learn classes in python and I am looking for problems about them. Are there any good online sites that I can find problems about them. If they also contain solutions, that would be great, but if not that is also okay.

Problems can have the form like

An administrator is a special kind of user. Write a class called Admin that inherits from the User class you wrote in Exercise 9-3 (page 166) or Exercise 9-5 (page 171). Add an attribute, privileges, that stores a list of strings like "can add post", "can delete post", "can ban user", and so on. Write a method called show_privileges() that lists the administrator’s set of privileges. Create an instance of Admin, and call your method

Write a separate Privileges class. The class should have one attribute, privileges, that stores a list of strings as described in Exercise 9-7. Move the show_privileges() method to this class. Make a Privileges instance as an attribute in the Admin class. Create a new instance of Admin and use your method to show its privileges.


etc.
 
Physics news on Phys.org
jedishrfu said:
There’s always the www.rosettacode.org site where a variety of tasks are written in a multitude of languages including python.
I have looked at it, but it seems there is not much problem about it
 
Pick a rosetta task and solve it in python. There are quite a few to choose from. In some cases, there is no python solution so they would welcome a solution that works.

one thing to be aware of is that some examples are not the best examples for the specific language so if you saw a poorly written python solution you could submit your better or alternate solution.
 
I found this online book with examples and questions.

https://scipython.com/book/

A big part of programming though is reading other people’s code so you could find python projects and try to find nuggets of knowledge in the project code like style, naming conventions and python language features. I've found really odd stuff in popular python projects like numpy and sci py for example.

there’s a cool python project called bpytop that implements a fancy version of the Linux top command in python.