What is the difference between a static method and class method in Python?

What are some simple-to-moderately challenging Python programming ideas or examples I can use to practice?

  • I have an upcoming exam for my computer science class and I'm still pretty novice when it comes to creating programs. I have a strong desire to learn python and just become a better programmer overall so I was hoping some people had any ideas or examples of python programs that I can attempt at creating and hopefully help me not just on my exam but on my knowledge of python as well. I emphasize on simple to moderately challenging programs because unfortunately my class has been very limited in teaching python and mostly focused more on Alice instead. To help clear things I've provided an example of a question straight from my assignment for people to reference when providing any ideas or examples. "Write a module 'car.py' that contains a class named Car that has the following data attributes: __year_model __make __speed The __init should accept year 'model' and 'make' as arguments. Assign these values to their corresponding attributes and assign 0 to __speed. The class should also have the following methods: accelerate: add 5 to the speed data attribute each time it is called brake: subtract 5 from the speed data attribute each time it is called get_speed: return the current speed Write a program named 'user_car.py' that calls the accelerate method 5 times. After each call get the current speed of the car and display it. Then call the brake method 5 times and do the same" As you can see the type of work in my class is very limited, and in fact, many questions I see on this website relating to python are completely foreign to me. So I'm just hoping a kind fellow can help aid me in my studies by creating a program similar or even more challenging than the one above. But not too challenging please! :)

  • Answer:

Mohammad Rafi at Quora Visit the source

Was this solution helpful to you?

Other answers

On second thought, interacting with the Google Geocoding API might be a little complex unless you know all about the dictionary and list data types, urllib & json modules, and how to hack strings together. I just wrote up a class and will post it (not sure how it'll format in a comment). You can either look through it and guess at how it works, or attempt to write your own and then use this for hints. My level of Python is intermediate, so I'm sure there are things here I could fix myself: import urllib import json class GoogleGeo(object): google_api = 'http://maps.googleapis.com/maps/api/geocode/json?' def __init__(self, address, sensor=True): self.address = 'address=' + address self.sensor = '&' + 'sensor=' + str(sensor).lower() self.json_response = json.loads(urllib.urlopen(self.google_api + self.address + self.sensor).read()) def get_lat(self): return self.json_response['results'][0]['geometry']['location']['lat'] def get_lon(self): return self.json_response['results'][0]['geometry']['location']['lng']

Robert Dewey

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.