Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Making a game called Lunar Lander on Python. In this game, you are attempting to land a lunar module (LM) on the moon. At the

Making a game called Lunar Lander on Python. In this game, you are attempting to land a lunar module (LM) on the moon. At the start of the game, the LM is 1000 meters off the surface of the moon, and it is moving at a velocity of 40 m/sec towards the surface. You have 25 units of fuel remaining. Your goal is to reach the surface (altitude 0) at less than 5 m/sec before running out of fuel. It is OK for the altitude to be less than zero so long as the velocity is below 5 m/sec (a small thump), otherwise it is a Really Bad Day (a big crash).

Your program must ask for the amount of fuel to burn for the next second of flight (this is a float that must be greater than or equal to zero). Whatever amount of fuel you enter will modify the altitude and velocity, as well as the fuel remaining. Your instruments will then be updated and printed out, and you will be asked for the amount of fuel to burn for the next second. This process repeats until you land, crash, or run out of fuel. If you ask for more fuel to be burned than what you have left, you will burn all remaining fuel. When your fuel tank is empty, the program will no longer ask you for fuel but will continue to update your instruments continuously until you either land or crash.

Your velocity will decrease by 4 times the amount of fuel you burn, but will also increase by 2 due to acceleration from the moons gravity (that is, 2 m/sec2 for one second increases velocity by 2 m/sec).

Your altitude will decrease by the velocity value (velocity is in m/sec but since each step is one second long, the seconds cancel, leaving meters).

Specifications:

You are to use the following framework for your program. You will need to fill in the two functions GetFuel and Main with your own code (no other functions are needed or allowed):

For function GetFuel:

The purpose of function GetFuel is to display the contents of parameter variable Message (a string) on the console while asking for a float value to be input. The value of parameter Message will be passed in from Main you will not use a literal string in the input statement!

Your code must not crash if the user enters something which is not a valid float value (you will have to use try-except), and must continue to ask the user for a new value if they enter something less than zero. That is, this function will not exit until it has been given a valid positive or zero float value.

Your code must assign the value to variable Answer so that it may be returned to the calling routine as shown in the template above.

When you write this function, test it independently of your game. Load your program and type GetFuel("Enter Fuel") or some other string at the prompt. Here are a couple sample runs showing what happens if I enter an invalid float value, an invalid input, and a valid input, as well as different string values to go into parameter Message:

>>> GetFuel("Enter Fuel --- ") Enter Fuel --- -7 Enter Fuel --- Money Enter Fuel --- 10 

>>> GetFuel("BOOM ") BOOM 6.7 6.7

For function: Main

Part 2 Function Main (the game)

In function Main you will need three variables to represent the current altitude, the current velocity, and the amount of remaining fuel.

Initially, assign 1000.0 to the altitude, 40.0 to the velocity, and 25.0 to the fuel. Print out these values.

Next, do a loop that runs as long as the altitude is greater than zero. Inside the loop, if you still have fuel remaining in the tank ask for the amount of fuel to burn (that is, call GetFuel); otherwise the amount of fuel to burn is automatically set to zero. If the amount requested is more than what it available, set the fuel to burn to the available amount. Subtract the amount of fuel to burn from your remaining fuel. Subtract 4 times the fuel to burn from the velocity, but add 2 for the acceleration due to gravity. Subtract the velocity from the altitude. Finally, print out the altitude, velocity, and remaining fuel.

After the loop, youve either landed or crashed. A crash is when the velocity as you hit the surface is greater than 5 m/second. Otherwise, you landed safely. Print out the result: did you land or crash?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

List any five design issues of the object-oriented language.

Answered: 1 week ago

Question

3. How has Starbucks changed since its early days?

Answered: 1 week ago