Question

In Python, write a program that uses a class to represents a spaceship. A spaceship has...

In Python, write a program that uses a class to represents a spaceship. A spaceship has some amount of jets, landing gear, parachutes and astronauts. It must leave Earth’s gravity, so it must use all its jets to propel itself off Earth. The spaceship will spend some time exploring before returning to Earth. When it returns to Earth, it will use its parachute and landing gear to land safely. Make sure that those are extended before landing!

Sample output:        Your spaceship has 5 astronauts, 2 jets, stored landing gear and parachute.

The spaceship is taking off!

Your spaceship is exploring...

Your spaceship is heading back to Earth.

Oh no! You’re landing gear and parachute weren’t extended! The expedition ended in failure.

Sample output:        Your spaceship has 10 astronauts, 4 jets, stored landing gear and parachute.

The spaceship is taking off!

Your spaceship is exploring...

Your spaceship is heading back to Earth.

The landing gear and parachute have been extended!

Your ship has arrived safely back on Earth.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Thanks for the question.

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change.If you are satisfied with the solution, please rate the answer.

======================================================================================

class SpaceShip():
    
    # marking the gear and parachutes as optional with default values as False
    def __init__(self,astronauts,jets,gear=False,parachutes=False):
        self.__astronauts=astronauts
        self.__jets=jets
        self.__gear=gear
        self.__parachutes=parachutes
    # getter functions
    def getAstronauntsCount(self):
        return self.__astronauts
    def getJetsCount(self):
        return self.__jets
    def getGear(self):
        return self.__gear
    def getParachutes(self):
        return self.__parachutes

# takes in a SpaceShip object and simulate the launching of spaceship, explortion and return to earth
def goOnMission(spaceship):
    print('Your spaceship has {0} astronaunts, {1} gets, stored landing gear and parachute'.\
          format(spaceship.getAstronauntsCount(),spaceship.getJetsCount()))
    print('The spaceship is taking off!')
    print('Your spaceship is exploring...')
    print('Your spaceship is heading back to Earth.')
    if spaceship.getGear() is not True or spaceship.getParachutes() is not True:
        print('Oh no! You’re landing gear and parachute weren’t extended! The expedition ended in failure.')
    else:
        print('The landing gear and parachute have been extended! Your ship has arrived safely back on Earth.')


def main():
    # don t pass the value of gear and parachutes, it will default to False
    spaceX = SpaceShip(5,2)
    #  pass the value of gear and parachutes as True
    spaceY=SpaceShip(10,4,True,True)
    goOnMission(spaceX)
    print()
    goOnMission(spaceY)

main()

===================================================================================

thanks !!

Add a comment
Know the answer?
Add Answer to:
In Python, write a program that uses a class to represents a spaceship. A spaceship has...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using Java, write a program that uses a class to represents a spaceship. A spaceship has...

    Using Java, write a program that uses a class to represents a spaceship. A spaceship has some amount of jets, landing gear, parachutes and astronauts. It must leave Earth’s gravity, so it must use all its jets to propel itself off Earth. The spaceship will spend some time exploring before returning to Earth. When it returns to Earth, it will use its parachute and landing gear to land safely. Make sure that those are extended before landing! Sample output: Your...

  • Python Program Eratosthenes of Cyrene lived approximately 275-195 BC. He was the first to accurately estimate...

    Python Program Eratosthenes of Cyrene lived approximately 275-195 BC. He was the first to accurately estimate the diameter of the earth. For several decades he served as the director and chief librarian of the famous library in Alexandria. He was highly regarded in the ancient world, but unfortunately only fragments of his writing have survived. The algorithm described for this assignment is known as the Sieve of Eratosthenes. The algorithm is designed to find all prime numbers within a given...

  • Objective: Write a program that implements the Game of Life cellular automata system invented by John...

    Objective: Write a program that implements the Game of Life cellular automata system invented by John Conway. 1. Create two game grids of size at least 50x50. These grid cells can be either Boolean or integer. In the following, I’ll refer to these as gridOne and gridTwo. 2. Set all cells in both grids to false. 3. Start by initializing gridOne. Allow the user to specify two different ways of initializing the grid: 1) by specifying a pattern file to...

  • You will write the following files: mystack.h - contains the class definition for the mystack class....

    You will write the following files: mystack.h - contains the class definition for the mystack class. mystack.cpp - contains the definitions for member functions of the mystack class. inpost.cpp - contains your convert() function. inpost.h - contains the function prototype for convert() so that the main() can call it. Each of the files (with the exception of inpost.h) is described in more detail below. All header files should contain header guards to prevent them from being included multiple times in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT