Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Do NOT use while True while coding this. please explain each step a little. thank you! Framework You are to use the following framework for

Do NOT use while True while coding this. please explain each step a little. thank you! image text in transcribed
image text in transcribed
image text in transcribed
Framework You are to use the following framework for your program. You will need to fill in the two functions Get Fuel and Main with your own code (no other functions are needed or allowed): # Your name - Lab #2 - March ??, 2021 def GetFuel (Message): Code to get a float value from the user return Answer def Main() : Your game code goes here return Part 1 - Function GetFuel The purpose of function Get Fuel 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 Get Fuel ("Enter Fuel ") or Get Fuel ("I like Frogs ") (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: Part 1 -Function GetFuel The purpose of function Get Fuel 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-excepty, 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 Get Fuel ("Enter Fuel ") or Get Fuel ("I like Frogs ") (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 -4 Frog Enter Fuel 5 5.0 The value returned in Answer >>> GetFuel ("I like Frogs I like Frogs 6.7 6.7 The value returned in Answer - Enter Fuel ") This assignment takes us back to the text-based games of the early 1970s, called "Lunar Lander" (this was one of the first games I ever played when I was starting out). 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 30) 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 crush). 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 moon's gravity (that is, 2 m/sec 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)

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

Students also viewed these Databases questions

Question

=+Are there shop stewards?

Answered: 1 week ago