This code is in Python As you know, when you attempt to get a number from the user by using something like: number = int(input(“Enter a number”) or number = float(input(“Enter a number”), if the user includes commas or a dollar sign in the number, the conversion will fail with an exception. Write a program that will include and use a function called getNumber( prompt ) that will do the following: 1) Use the standard input function to display the prompt and get the user’s input. 2) Use the string functions to remove any commas or dollar sign from the input. 3) Check for the presence of a decimal point. 4) If a decimal point is present, use the float conversion function to convert the modified input to float; otherwise, use the int conversion function to convert to an int 5) Return the number to the calling code.
This code is in Python
As you know, when you attempt to get a number from the user by using
something like:
number = int(input(“Enter a number”) or
number = float(input(“Enter a number”),
if the user includes commas or a dollar sign in the number, the conversion will fail
with an exception.
Write a program that will include and use a function called getNumber( prompt )
that will do the following:
1) Use the standard input function to display the prompt and get the user’s
input.
2) Use the string functions to remove any commas or dollar sign from the
input.
3) Check for the presence of a decimal point.
4) If a decimal point is present, use the float conversion function to convert
the modified input to float; otherwise, use the int conversion function to
convert to an int
5) Return the number to the calling code.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
I'm kind of new to python so I have never seen the "ord" operator (i can't remember the term) before. Can you explain it just so I can get a sense of what it does?