Question

In-class exercise: Write a program to parse the user's input, in the format of an integer...

In-class exercise: Write a program to parse the user's input, in the format of an integer followed by the word "million" or "thousand". Then use formatting to display the number with comma separators. For example:

Please enter a number using the word "thousand" or "million"
For example, "327 million" or "5 thousand"
327 million
327,000,000

Please enter a number using the word "thousand" or "million"
For example, "327 million" or "5 thousand"
10 thousand
10,000

Please enter a number using the word "thousand" or "million"
For example, "327 million" or "5 thousand"
75 million
75,000,000 
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program:

print('\nPlease enter a number using the word "thousand" or "million"')
print('For example, "327 million" or "5 thousand"')

x = input()

x_l = x.strip().split(' ')

if x_l[1] == 'thousand':
   val = int(x_l[0]) * 1000
else:
   val = int(x_l[0]) * 1000000

print("{:,}\n".format(val))

Execution and Output:

Add a comment
Know the answer?
Add Answer to:
In-class exercise: Write a program to parse the user's input, in the format of an integer...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a Visual C# program that will input the user's name and a message. The user...

    Write a Visual C# program that will input the user's name and a message. The user will be able to choose from an option of formatting tools to change the way the message (and only the message) will look. The user can choose from bold, underline, italic, along with several different color options. All changes the user selects will be displayed in the message textbox. Once the user selects the Finish button, the two pieces of information entered by the...

  • Write a program that first gets a list of integers from the input and adds them...

    Write a program that first gets a list of integers from the input and adds them to an array. The input begins with an integer indicating the number of integers that follow (Your program should work for any size of the array). Then, get the last value from the input, and output all integers less than or equal to that value by iterating through the array. Ex: If the input is: Enter the number of integers: 5 Enter integer 1:...

  • Write a program which asks the user to enter an integer. Use switch statement to write...

    Write a program which asks the user to enter an integer. Use switch statement to write out the numeric word (such as ONE) if the user's input is 1; (see the sample run output for the usr input 2 or 3); otherwise, write OUT OF RANGE. Below are few sample runs: If the user enters a 1, the program will print: ONE TWO THREE Or, if the user enters a 2, the program will print: TWO THREE Or, if the...

  • *****USING PYTHON*****Write a program that reads a number between 10,000 and 999,999 from the user, where...

    *****USING PYTHON*****Write a program that reads a number between 10,000 and 999,999 from the user, where the user enters a comma in the input. Then print the number without a comma. Here is a sample dialog; the user input is in italics Please enter an integer between 10,000 and 99,999: 23,456 23456

  • Exercise 1: Write a C++ program that asks the user to input an integer n followed...

    Exercise 1: Write a C++ program that asks the user to input an integer n followed by n other characters that will be stored in an array. We suppose here that the user will input only lowercase characters between ‘a’ and ‘z’. We also suppose that the user will input different characters. The program will then sort these characters according to an increasing order of their alphabetical order. In this exercise, feel free to use selection sort, insertion sort, or...

  • Write a program that prompts the user for an integer that the player (maybe the user,...

    Write a program that prompts the user for an integer that the player (maybe the user, maybe someone else) will try to guess. If the player's guess is higher than the target number, the program should display "too high" If the user's guess is lower than the target number, the program should display "too low" The program should use a loop that repeats until the user correctly guesses the number. Then the program should print how many guesses it took....

  • Write a program that will accept an integer as input from the user and test if...

    Write a program that will accept an integer as input from the user and test if that input is an even number. It should also test if the input is evenly divisible by 6. The program should display “Even” if the user’s input is even. It should additionally display “divisible by 6” if the user’s input is evenly divisible by six. #include <iostream> using namespace std; int main(){      return 0; } Convert the following switch statement to an if-...

  • PART TWO Write a program which will populate an integer ArrayList with user input, and then...

    PART TWO Write a program which will populate an integer ArrayList with user input, and then provide a menu of various operations to perform on that ArrayList. The first step is to have the user push a bunch of integers into a ArrayList. The second step is to perform various operations on that ArrayList. Your input must be in the format below. The user can enter either a positive integer or -99 to quit. The menu to present is: Sum...

  • Write a Python program that converts an input file in FASTA format, called "fasta.txt", to an...

    Write a Python program that converts an input file in FASTA format, called "fasta.txt", to an output file in PHYLIP format called "phylip.txt". For example, if the input file contains: >human ACCGTTATAC CGATCTCGCA >chimp ACGGTTATAC CGTACGATCG >monkey ACCTCTATAC CGATCGATCC >gorilla ATCTATATAC CGATCGATCG Then the output file should be human ACCGTTATACCGATCTCGCA chimp ACGGTTATACCGTACGATCG monkey ACCTCTATACCGATCGATCC gorilla ATCTATATACCGATCGATCG FASTA format has a description (indicated with a '>') followed by 1 or more lines of a DNA sequence. PHYLIP format has a description...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT