Question

You are writing a silly calculator. First, you ask the user to enter an integer. Then...

You are writing a silly calculator. First, you ask the user to enter an integer. Then you ask them if they would like to know if that number is even, for it to be squared, or for it to be multiplied with another number. The user will input "even" "square" or "multiply" for these options, respectively.

For this question, we do not provide pseudocode -- consult with the sample output to determine how your program should work specifically.

linux3[6]% python3 hw2_part2.py Enter an integer: ​34

Would you like to know if this number is even, square it, or multiply it with another number? ​square

The square of this number is: 1156

linux3[7]% python3 hw2_part2.py Enter an integer: ​45

Would you like to know if this number is even, square it, or multiply it with another number? ​scallop

I don't know what you're talking about.

linux3[8]% python3 hw2_part2.py Enter an integer: ​19

Would you like to know if this number is even, square it, or multiply it with another number? ​even

It is odd!

linux3[9]% python3 hw2_part2.py Enter an integer: ​23

Would you like to know if this number is even, square it, or multiply it with another number? ​multiply

What is the other number? ​7

23 times 7 is 161

Homework Answers

Answer #1
n = int(input('Enter an integer: '))
choice = input('Would you like to know if this number is even, square it, or multiply it with another number? ​')
if choice == 'even':
    if n % 2 == 0:
        print("It is even!")
    else:
        print("It is odd!")
elif choice == 'square':
    print("The square of this number is:", n * n)
elif choice == 'multiply':
    n2 = int(input('What is the other number? ​'))
    print(n, "times", n2, "is", n * n2)
else:
    print("I don't know what you're talking about.")
Know the answer?
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
Similar Questions
(8 marks) Write a program to ask user to input an integer and display the special...
Write a program to ask user to input an integer and display the special pattern accordingly. REQUIREMENTS The user input is always correct (input verification is not required). Your code must use loop statements (for, while or do-while). Your program should use only the following 3 output statements, one of EACH of the followings: System.out.print("-"); // print # System.out.print("+"); // print + System.out.println(); // print a newline Your code must work exactly like the following example (the text in bold...
(1) Ask the user to input a character. You will draw your right triangle with this...
(1) Ask the user to input a character. You will draw your right triangle with this character. (2) Ask the user to input the number of rows (integer). This will also signify the number of characters at the base of the triangle. (3) Use a nested loop to draw the triangle. The first line will only have one character but will now need to output enough spaces such that the character is output at the end of the row instead...
Assembler lanaguage program   The program is to prompt the user to enter a number between 2...
Assembler lanaguage program   The program is to prompt the user to enter a number between 2 and 100. Reject any invalid user inputs and terminate the program if invalid inputs are entered. Print each even number from 2 to the user entered number. Sum these even numbers and print the sum. Print each odd number from 1 to the user entered number. Sum these odd numbers and print the sum. Exit the program when the output is complete. The output...
Python: Write a program that prompts the user to enter a positive integer value, and compute...
Python: Write a program that prompts the user to enter a positive integer value, and compute the following sequence: • If the value is even, halve it. • If it's odd, multiply by 3 and add 1. • Repeat this process until the value is 1, printing out each value. • Then print out how many of these operations you performed. If the input value is less than 1, print a message containing the word Error and exit the program....
."Ask the user to input a number.  You must use an input dialog box for this input....
."Ask the user to input a number.  You must use an input dialog box for this input. Be sure to convert the String from the dialog box into an integer (int). The program needs to keep track of the smallest number the user entered as well as the largest number entered. Use a Confirm dialog box to ask the user if they want to enter another number. If yes, repeat the process. If no, output the smallest and largest number that...
One way to represent a very large integer (one that won't fit into a variable of...
One way to represent a very large integer (one that won't fit into a variable of type short, int, or even long) is to use an array. The array is of type int, so each element in the array can hold an integer -- we will store just one digit of our number per array element. So if a user entered 2375, it might be stored as -------------------------- | 2 | 3 | 7 | 5 | ... | --------------------------...
Create a JAVA project named IA01 that does the following: Display a randomly-determined even number to...
Create a JAVA project named IA01 that does the following: Display a randomly-determined even number to the user The number should be between 2 and 10 inclusive Prompt the user to enter the value of half that number You can assume the user will enter valid numbers, not letters or gibberish They only get one chance to answer per number Tell the user if they are right or wrong Ask the user if they want to try another even number...
Part II - Pi Calculation implementation. If you watch the Discovery or Sci-Fi channel you will...
Part II - Pi Calculation implementation. If you watch the Discovery or Sci-Fi channel you will find dozens of alien conspiracy shows that reference Pi as something so advanced that it must be alien.  The number πis a mathematical constant, the ratio of a circle's circumference to its diameter, commonly approximated as 3.14159. So you could graph the value or calculate an approximate value using the series given below: Pi = 4 * (1/1 – 1/3 + 1/5 – 1/7 +...
For this assignment you will implement a simple calculator or interpreter that reads arithmetic expressions from...
For this assignment you will implement a simple calculator or interpreter that reads arithmetic expressions from a file. Specifically, you will implement the following function: /* * Reads one arithmetic "expression" at a time from a file stream, computes, then * returns the result. If there are additional expressions in the file, they are * read and computed by successive calls to “calculator”. * * “Expressions” are groups of operations (add, subtract, multiply, divide). Your * calculator will read and...
1. Vim commands: a. How do you auto indent your program? b. Explain what the following...
1. Vim commands: a. How do you auto indent your program? b. Explain what the following commands do: dd, y3, p, :set cindent (1 pt) VIM exercises These exercises on the computer need to be repeated by each student in the pair. This is to ensure that both students understand how to get around in Linux!!! For this part of the lab, you will create a .vimrc file that will help you develop your C++ programs using VIM. First, we...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT