![dubouuu](/avatars/252.jpg)
dubouuu
09.02.2021 •
Computers and Technology
Part B
There are many different ways that a user could tell us that he or she would like to add two numbers in our calculator program. The user could type “add”, “Add”, “ADD”, or “+”, to name a few possibilities. Of course, as humans, we know exactly what is meant, even if the word is capitalized. But the Python Interpreter can’t tell that “add” is the same as “Add”.
We can use a list to make our program a bit more robust. We can also use the IN operator to check for certain values in that list. Take a look at this if statement’s opening line:
if operation in [“add”, “Add”, “ADD”, “+”]:
Make those changes in your program and verify that it works.
Consider all of the possible words the user might enter to subtract, multiply, or divide.
Rewrite the first lines of each of your if statements to use lists.
Thoroughly test your new program, trying out each of the four operations.
Share the link to your Python code in REPL.it with your teacher by clicking on the share button and copying the link.
Solved
Show answers
More tips
- A Animals and plants Money Tree Care Secrets: How to Keep Your Plant Thriving...
- F Food and Cooking Delight for Gourmets: How to Prepare Liver Pate...
- S Style and Beauty How to braid friendship bracelets?...
- H Health and Medicine Mercury Thermometer Danger: What to do when a thermometer breaks?...
- F Food and Cooking Which Calamari Salad is the Most Delicious?...
- S Society and Politics 10 Tips for Boosting Your Self-Esteem...
- F Food and Cooking The Most Delicious and Simple Fish in Batter Recipe...
- H Health and Medicine What is Autism? Understanding the Basics of This Neurodevelopmental Disorder...
- P Philosophy How to Develop Extrasensory Abilities?...
- S Style and Beauty Don t Sacrifice Your Brows: How to Properly Pluck Stubborn Hairs...
Answers on questions: Computers and Technology
- C Computers and Technology FOR DIGITAL DESIGN/ PHOTOGRAPHY The two types of digital cameras are: shutterless & Camera Phones Iphones & Electronic Film DRSP & Mirrored DSLR & Mirrorless...
- C Computers and Technology Your friend is applying for a job at your company she ask you to recommend her she wants to tell your boss that you have worked with her before even though that is not true...
- C Computers and Technology Which tools did early communities first use to help them grow enough food to feed their residents and have a surplus at times? A)tractors, combines, and GPS locators B)polished...
- E English The legislature had enacted laws enabling to discharge their obligations more easily, the courts put an end to such practices by stipulating that no state could enact laws...
- E English How did understanding of this phenomenon brain catch his first fish...
- M Mathematics Jessie made 312 mini energy bar.she put 24 in each bag.she plans to sell each bag for $6...
- C Chemistry Which two terms relate and why? compound, ion, proton...
- B Biology Where to get answers for sixth grade science over matter...
- B Biology The main products of the dark reactions calvin-benson cycle ) of photosynthesis are a. o2 and atp b. sugar and water c. co2 and glucose d. atp and water...
- M Mathematics Arecipe for 1 pumpkin pie calls for 1\1\4 cups of sugar. alana has only 1/2 cup of sugar and she had to make 4 pies. how much sugar does she need to make all 4 pies....
Ответ:
The Python programming language is a great tool to use when working with numbers and evaluating mathematical expressions. This quality can be utilized to make useful programs.
This tutorial presents a learning exercise to help you make a simple command-line calculator program in Python 3. While we’ll go through one possibile way to make this program, there are many opportunities to improve the code and create a more robust calculator.
We’ll be using math operators, variables, conditional statements, functions, and handle user input to make our calculator.
Prerequisites
For this tutorial, you should have Python 3 installed on your local computer and have a programming environment set up on the machine. If you need to either install Python or set up the environment, you can do so by following the appropriate guide for your operating system.
Step 1 — Prompt users for input
Calculators work best when a human provides equations for the computer to solve. We’ll start writing our program at the point where the human enters the numbers that they would like the computer to work with.
To do this, we’ll use Python’s built-in input() function that accepts user-generated input from the keyboard. Inside of the parentheses of the input() function we can pass a string to prompt the user. We’ll assign the user’s input to a variable.
For this program, we would like the user to input two numbers, so let’s have the program prompt for two numbers. When asking for input, we should include a space at the end of our string so that there is a space between the user’s input and the prompting string.
number_1 = input('Enter your first number: ')
number_2 = input('Enter your second number: ')
After writing our two lines, we should save the program before we run it. We can call this program calculator.py and in a terminal window, we can run the program in our programming environment by using the command python calculator.py. You should be able to type into the terminal window in response to each prompt.
Output
Enter your first number: 5
Enter your second number: 7
If you run this program a few times and vary your input, you’ll notice that you can enter whatever you want when prompted, including words, symbols, whitespace, or just the enter key. This is because input() takes data in as strings and doesn’t know that we are looking for a number.
Explanation:
Hope This helps with your coding
( If it doesn't then sorry)
Ответ:
What Is a Harmonic Mean? The harmonic mean is a type of numerical average. It is calculated by dividing the number of observations by the reciprocal of each number in the series. Thus, the harmonic mean is the reciprocal of the arithmetic mean of the reciprocals.
Explanation: