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.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter14: Exception Handling
Section: Chapter Questions
Problem 5PE
icon
Related questions
Question
100%

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. 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

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?

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Exception Handling Keywords
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning