Hi everyone,
I just started working with Python and programming in general (i chose it as a school subject for this year) and i received a task(scroll a bit more down).. since im a total newbie with Python in general.. i was hoping someone could please explain this task in detail, I am writing an exam over this exact same task in a few days time but i do not fully understand it

here is my task:
" Task - Classes And Instantiating Objects Based On The Class

Build a class called Corvette
Public Methods of Corvette






Instantiate Your Object

Generating A Random Number In Python

Determining Likelihood Of Something Occuring

Build a class called Corvette (represents one of the new navy frigates)

Properties of the Corvette


Public Methods of Corvette

ShootExocetMissile(TargetName, DistanceAway)

Remember to decrement NumberOfExocetMissiles
What do you do when you are out of missiles ?
Return 0 if successful else 1 if fails. Use random number generator to decides success or fail with 75 % chance of success

EvadeTorpedoes(DirectionToTurn=[port, starboard], Speed=[Full, Half, Stop], FireCounterMeasures=True/ False, TorpedoeDirection=[port, starboard])

If TorpedoDirection = port and DirectionToTurn = port then LikelihoodOfHit = 20 % otherwise 80 %

If TorpedoDirection = starboard and DirectionToTurn = starboard then LikelihoodOfHit = 20 % otherwise 80 %

If hit then call private method AbandonShip and return 1 else return 0 (means ship not hit)

Private Method of Corvette


See if you can get the PC to make a noise for 10 seconds and then return control to calling stub

Instantiate Your Object

Give the object values

Change the captains name

You have 10 Exocet missiles

Shoot two Exocet missiles. What happened to each missile, did they hit or not

Show NumberOfExocetMissiles

A torpedo is shot at you - do you get hit ?

Generating A Random Number In Python

import random
random.randint(0, 100) # generate random integer between 0 and 100

Determining Likelihood Of Something Happening

Suppose there is a 20 % chance (likelihood) of it raining.

To program this we generate a random number (integer) whose value lies between 0 and 1, and if this number is <= 20 then it will rain

def WillEventOccur(ChanceOfEventOccuring = 20): # 20% chance of event occuring
import random
if random.randint(0,100) <= ChanceOfEventOccuring: # test if random number <= 20
return True # event has occured
return False # event does not occur


thanks in advance for any help, i truly appreciate it.

Oh yes, i forgot to mention i have tried this task at school.. im further than most of my class mates but nearly none of us understand it. I only managed to create a small part of the class without it actually being able to do anything yet.

Well, the usual procedure here is to start with your code. Post it here and then we can give pointers and such.


here is the code i have done so far:

class Corvette():
        Corvette Class
    def __init__(self,ShipName="",CaptainsName="",NumberOfExocetMissiles=""):
        self.Shipname = Shipname
        self.captainsName = CaptainsName
        self.NumberOfExocetMissiles = NumberofExocetMissiles

    def ShootExocetMissile(self, TargetName="", DistanceAway="")

as you can see, it isnt much. The teacher doesnt really explain anything and expects us to find out on our own. Can someone please explain to me how i can do the rest of the task?
I am writing an exam about classes which will have the exact same task in.. pls. help!

Start with defining the public and private members. You should also read your own post. There is duplication re defining the class named "Corvette". Rework it so that things are clear and only defined once.