18 Jun Tuesday 17:30 Python Homework 21.06.15.
Question 1:
Create a Tank class which have the attributes of:
- name
- direction(use ‘up’, ‘down’, ‘left’ or ‘right’)
- x position and
- y position
The class also have the following method:
- move (direction, steps) method can change the x or y position base on the direction and steps. it will also change the direction tank facing. (‘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 and facing up
- __str__() method
You need write main program to create tank object from Tank class, you need to use the method of move and use print(tank object) to print out the tank’s current x, y position and its direction after each move.
Question 2:
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.
Sorry, the comment form is closed at this time.