Question
Using Python Project 2 - Soft Landing - Required Functions -------------------------------- This assignment is worth 18 points and should be done with your partner: 15
Using Python
Project 2 - Soft Landing - Required Functions
--------------------------------
This assignment is worth 18 points and should be done with your partner:
15 points autograded for correctness
3 points graded by TA for Style
The TAs will be grading your final mp2R.py file for Style. Style points will be given for:
Readability - Use Comments!
Following Style Rules
Docstrings
Meaningful Variable Names
-------------------------------------------------
Function get_initial_conditions [5 points autograded]
Use the Design Recipe to define a function get_initial_conditions which consumes no parameters and asks the user to enter the landers initial altitude (float), speed (float), and fuel (int). Your function should return a list containing the altitude, speed, and fuel (in that order). You must check the users entries as follows and keep asking the user for values until an acceptable one is given. Include a docstring!
For float values, the user must only enter digits (at least one). They can additionally enter a single decimal if desired and can enter a - symbol in front of the digits if a negative numbers is desired.
For integer values, the user must only enter digits (at least one).
The altitude and fuel may not be negative.
Hint: You may want to define the get_float , get_integer and is_float functions in the Optional Helper Functions assignment first. Then you can copy and paste them into this file and call them from this function.
-----------------------------------
Function save_history(history_list,landing_num) [6 points autograded]
Use the Design Recipe to define a function save_history which consumes two parameters, a nested list and an int representing the current landing attempt. The function should open a new file named 'LandingNN.csv' where NN is two digits representing the current landing attempt. The first line should contain the number of sublists in the nested list. Each sublists should be written to the file on its own line with its values separated by commas. This function should close the file when its finished writing to it. Include a docstring!
For example:
Test | contents of file Landing01.csv |
---|---|
history =[ [3.61, 2.98, 15], [3.01, 0.6, 14], [0.79, 2.22, 14], [0, 3.84, 14]] save_history(history,1) | 4 3.61,2.98,15 3.01,0.6,14 0.79,2.22,14 0,3.85,14 |
Note: When running your code, you can call the pre-defined function show_file_contents(filename) to view the contents of the file you saved.
For example - to view the contents of' Landing01.csv' use this statement:
show_file_contents('Landing01.csv')
----------------------------------
Function get_response [ 4 - points autograded]
Use the Design Recipe to define a function get_response(valid_entries,prompt), which consumes two strings. This function keeps asking the user to enter a value using the prompt as the input message to the user until they enter one of the characters in the string (upper or lower case), then return the lower-case version of character.
For example:
Test | Input | Result |
---|---|---|
print(get_response("qra","Enter a 'q' to quit or 'r' to repeat")) |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started