TORONTO KIDS COMPUTER CLUB | Friday Python Practice 19:00 – 22.12.09
21547
post-template-default,single,single-post,postid-21547,single-format-standard,ajax_fade,page_not_loaded,,qode-theme-ver-7.6.2,wpb-js-composer js-comp-ver-6.10.0,vc_responsive

Friday Python Practice 19:00 – 22.12.09

14 Dec Friday Python Practice 19:00 – 22.12.09

Question 1:

Make a class definition for a  BankAccount. It should have attributes for :

– its name (a string),
– account number (a string or integer),
– and balance (a float).

It should have methods to:

– make deposits with displaying the balance,
– and make withdrawals with displaying the balance.


Hint:


Question 2:
Create a Tank class which have the attributes of:

  • model
  • direction(use ‘up’, ‘down’, ‘left’ or ‘right’)
  • x position and
  • y position

The class also have the following method:

  • move () method can change the x or y position by 10 base on the tank’s direction. (‘up’ and ‘down’ can change y position while ‘left’ and ‘right’ can change x position)
  • Using __init__() to Initial the tank to make sure it start from x position of 0, y position of 0
  • __str__() to return a string information of the tank, so you could print the tank object

You need write main program to create tank object from Tank class, you need to use the method of move and use print() to print out the tank’s current x, y position and its direction after each move.


Question 3:
Create a Student class and make the following methods to :

  • __init__() – Initialize it with name and roll number.
  • __str__() – Display all information of the student.
  • setAge() – It should assign age to student.
  • setMarks() – It should assign marks to the student.
No Comments

Sorry, the comment form is closed at this time.