Answered step by step
Verified Expert Solution
Question
1 Approved Answer
using python Challenge 2: Now, let's write a new program to help our mountaineer users identify their goal - which base camp they want to
using python
Challenge 2: Now, let's write a new program to help our mountaineer users identify their goal - which base camp they want to aim for when climbing Mount Everest! INPUT: Use the input() function to ask the user which basecamp they want to reach. Note! You can leave the user input as a string - which is the default data type retrieved from the input() function. Valid input can be "1", "2", "3", "4", "5". Or the user can enter can enter "1", "II", "III", "IV", or "V". All of the above are VALID inputs because they represent the five camps when climbing Mount Everest. Store the user input into a new variable called base_goal. (base_goal will store a string data type, as mentioned above). PROCESSING: First, we want to check if the user entered a value that contains only digits or alphanumeric characters (Hint! Use a builtin python function to check this! This was covered in lecture -- see Chapter 3.8 Strings of your textbook.) There will two cases here. First, we need to check if the input was valid. (Let's call this case 1). Second, if the input was NOT valid, this will be case 2. E.g. If the user entered something invalid (e.g. 1!@#). If case 2 happens, print "Invalid format. Should contain only digits or alphanumeric characters." If the input was valid (case 1), let's do some further tests about the input to see the user inputted a digit or an alphabet character. (Hint! You'll need to use nested branches here! Because you are just now learning these concepts, we indent it for you here to give you a hint. In future challenges, you'll need to figure out how to structure the nested branches for yourself!) If the user entered a value that contains only digits (Hint! Use a builtin Python function to check this!), print the Roman number equivalent of that digit. E.g. If the user entered "4", we want to print "IV". E.g. If the user entered "1", we want to print "1". If the user entered a value that contains only digits, but it is a digit that is NOT "1","2","3","4","5", print "Invalid. The number must be between 1 and 5.". If the user entered a value that contains is a Roman number, print the number equivalent of that Roman number E.g. If the user entered "IV", we want to print "4". E.g. If the user entered "III", we want to print "3". If the user entered a Roman Number that is not I, II, III, IV, or V, print "Invalid.The Roman number must be I, II, II, IV or V". Finally, if the user entered a value that is a combination of digits and alphabet characters, print "Almost! Must be either a digit or an alphabet character." Hint! Because the built-in Python functions you will use for the above steps work on string data types, we don't need to do any type casting to integers here. We can simply use the default data type of string, retrieved from the input() function, and compare strings to strings. Make sure you understand this! SAMPLE INPUT AND EXPECTED OUTPUT: Below, you'll see some examples of correct (valid) input, and then some examples of invalid input. helenaihe@helenaihe - ThinkPad-E470:-/Desktop/Python1105/1105$ python3 p22.py What basecamp is your goal? Enter a number between 1 and 5, or between I and V: V helenaihe@helenaihe - ThinkPad-E470:-/Desktop/Python1105/1105$ python3 p2_2.py What basecamp is your goal? Enter a number between 1 and 5, or between I and V: 3 III helenaihe@helenaihe - ThinkPad E470:-/Desktop/Python1105/1105$ python3 p22.py! What basecamp is your goal? Enter a number between 1 and 5, or between I and V: II helenaihe@helenaihe - ThinkPad E470:-/Desktop/Python1105/1105$ python3 p2_2.py What basecamp is your goal? Enter a number between 1 and 5, or between I and V: 112 Almost! Must be either a digit or an alphabet character. helenaihe@helenaihe - ThinkPad-E470:-/Desktop/Python1105/1105$ python3 p2_2.py What basecamp is your goal? Enter a number between 1 and 5, or between I and V: 4 IV helenaihe@helenaihe - ThinkPad E470:-/Desktop/Python1105/1105$ python3 p2_2.py, What basecamp is your goal? Enter a number between 1 and 5, or between I and V: 31 Almost! Must be either a digit or an alphabet character. helenaihe@helenaihe - ThinkPad-E470:-/Desktop/Python1105/1105$ python3 p2_2.py What basecamp is your goal? Enter a number between 1 and 5, or between I and V: -!#$@ Invalid format. Should contain only digits or alphanumeric charactersStep 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