← Back to Menus & Validation
Question 470
Kilometres And Miles
Kilometres And Miles
A letter menu: K) Kilometres to miles, M) Miles to kilometres, Q) Quit. Read the choice with the prompt Choice: , stripped and upper-cased with .upper() so k and K both work. Choice K reads a distance with the prompt Kilometres: as a float and prints it divided by 1.6 with two decimals (:.2f) followed by a space and miles; choice M reads with the prompt Miles: and prints the distance times 1.6 followed by km; Q prints Goodbye! and leaves the loop; anything else prints Unknown choice - try again.. Input: one line per choice or distance, ending with q or Q. Prompts are part of the output, so a result follows its distance prompt on the same line.
Expected Output:
K) Kilometres to miles M) Miles to kilometres Q) Quit Choice: Kilometres: 5.00 miles K) Kilometres to miles M) Miles to kilometres Q) Quit Choice: Miles: 8.00 km K) Kilometres to miles M) Miles to kilometres Q) Quit Choice: Goodbye!
= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
Menus & Validation
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.