1) As you have learned, you can use the input function to accept numbers. For ex
ID: 3589554 • Letter: 1
Question
1) As you have learned, you can use the input function to accept numbers. For example, the following code accepts a number and stores it in the variable named coin: coin-input('Enter a coin'); This works great if we want to enter a numeric value (like 25), but what if we wanted to enter a string, or word, like quarter? Well, input can handle that as well, but there is a bit of extra syntax. In order to allow the user to enter strings, we change the previous statement to: coin-input'Enter a coin's) Notice that extra 's'? It is an extra argument that we have placed in the input function to account for the user typing in a string. You can also think of it as the flag that allows input to accept strings. It is worth noting that when the 's' argument is provided, then entering a numeric value will most likely not produce the result you are expecting. a) Based on the above discussion, write the MATLAB code to ask the user toExplanation / Answer
Here is the answer for your question.
Based on the above discussion, the MATLAB code to ask the user
to enter a coin ('q' for quarter, 'd' for dime, 'n' for nickel,'p' for penny)
is
coin = input('Enter q for quarter, d for dime, n for nickel,p for penny','s')
Explanation:
The problem here is to accept q or d or n or p from the user.
But this is a character nothing but a string. As group of characters is a string.
So as per the discussion we have to give 's' as argument.
But we have to display to the user as Enter q for quarter, d for dime, n for nickel,p for penny.
So this will be the first argument. But here we have to understand that we can not put quotes before the letters and after the letters q or d or n or p because if we put quotes it will be treated as a string and that will be an argument.
So there will be too many arguments for that.
So the answer is
coin = input('Enter q for quarter, d for dime, n for nickel,p for penny','s')
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.