Question
I have to write this in Python and it must run in Python 3. The last two pictures are what I have so far please correct me if anything I have written so far is wrong.
anything interesting 6.8. Do addition Summary Now you will replace the pass statement inside the addition case of the iflelif ladder with something that actually does addition. Since the only number we have right now is the accumulator, you will need to ask the user for a number This number will be added to the value of the accumulator and then stored back into the accumulator. Do this 1. the in your iflelif ladder where choice 1 is handled this is for addition). 2. You can leave the comment where it is. 3. Delete the pass statement. 4. Get a number from the user, prompting with Enter a number: Convert the number to a float and store it in a variable. Name the variable something appropriate. Do not use the accumulator variable for this that variable already contains an important number. 5. Add the number in that variable to the accumulator variable and store the sum back into the accumulator variable. 6. Test your program. What do you expect should happen now when you run your program? Make sure it works. 6.9. Do subtraction write the next case in the iflelse ladder so that it is similar to the first case. Get a number from the user (a float, subtract it from the accumulator and store it b into the accumulator. Test it.
media%2F95c%2F95c26e89-3420-427e-a9ea-50
media%2F885%2F88543225-b251-41c4-a167-c0
0 0
Add a comment Improve this question Transcribed image text
Answer #1

NOTE: Your code seem to be correct with some duplicate code like you are asking about option twice. But as per your assignment i think you need to include other steps of doing addition, subtraction etc which i have finished here. Please check and let me know if you have any questions.

Code:
#!/usr/local/bin/python3

from math import sqrt

def main():
   question = 'What is your option? '
   contin = True
   opt = -1
   accum = 0.0
  
   while contin:
       print("Accumulator=",accum)
       print("Please Choose...")
       print("1)Addition")  
       print("2)Subtraction")
       print("3)Multiplication")
       print("4)Division")
       print("5)Square root")
       print("6)Clear")
       print("0)Exit")
       opt = int(input(question))
  
       if opt == 0:
           contin = False
       elif opt == 1:
           num = float(input("Enter a number? "))
           accum += num  
       elif opt == 2:
           num = float(input("Enter a number? "))
           accum -= num
       elif opt == 3:
           num = float(input("Enter a number? "))
           accum *= num
       elif opt == 4:
           num = float(input("Enter a number? "))
           accum /= num
       elif opt == 5:
           num = float(input("Enter a number? "))
           accum = sqrt(num)
       elif opt == 6:
           print("Clear")  
           pass
       else:
           print("Wrong option. Try again...")


if __name__=='__main__':
   main()

  
Execution and output:

Unix Terminal> python3 arithmetic.py
Accumulator= 0.0
Please Choose...
1)Addition
2)Subtraction
3)Multiplication
4)Division
5)Square root
6)Clear
0)Exit
What is your option? 1
Enter a number? 100
Accumulator= 100.0
Please Choose...
1)Addition
2)Subtraction
3)Multiplication
4)Division
5)Square root
6)Clear
0)Exit
What is your option? 2
Enter a number? 20
Accumulator= 80.0
Please Choose...
1)Addition
2)Subtraction
3)Multiplication
4)Division
5)Square root
6)Clear
0)Exit
What is your option? 3
Enter a number? 10
Accumulator= 800.0
Please Choose...
1)Addition
2)Subtraction
3)Multiplication
4)Division
5)Square root
6)Clear
0)Exit
What is your option? 4
Enter a number? 10
Accumulator= 80.0
Please Choose...
1)Addition
2)Subtraction
3)Multiplication
4)Division
5)Square root
6)Clear
0)Exit
What is your option? 5
Enter a number? 900
Accumulator= 30.0
Please Choose...
1)Addition
2)Subtraction
3)Multiplication
4)Division
5)Square root
6)Clear
0)Exit
What is your option? 6
Clear
Accumulator= 30.0
Please Choose...
1)Addition
2)Subtraction
3)Multiplication
4)Division
5)Square root
6)Clear
0)Exit
What is your option? 0

Add a comment
Know the answer?
Add Answer to:
I have to write this in Python and it must run in Python 3. The last...
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
  • i need these 2 question written in python. ---- US ). T R . Now for...

    i need these 2 question written in python. ---- US ). T R . Now for every episode of the 7 seven episodes of season 7. Your program has to ask the following questions about: • Ask the user for the episode number. • Ask the user for the episode title. • Ask the user for the episode director. • Ask the user for the number of U.S viewer (in millions) for this episode • Ask the user for the...

  • 3. Write Python statements that will do the following: a) Input a string from the user....

    3. Write Python statements that will do the following: a) Input a string from the user. *** Print meaningful messages along with your output.* b) Print the length of the String. Example input: The sky is blue. Correct output: The length of the string is 16 Incorrect output: 16 c) Print the first character of the string. d) Print the last character of the string. 4. Save the program. Double-check the left edge for syntax errors or warning symbols before...

  • Write a Python Program that displays repeatedly a menu as shown in the sample run below....

    Write a Python Program that displays repeatedly a menu as shown in the sample run below. The user will enter 1, 2, 3, 4 or 5 for choosing addition, substation, multiplication, division or exit respectively. Then the user will be asked to enter the two numbers and the result for the operation selected will be displayed. After an operation is finished and output is displayed the menu is redisplayed, you may choose another operation or enter 5 to exit the...

  • Hello! we are using Python to write this program. we are supposed to use loops in...

    Hello! we are using Python to write this program. we are supposed to use loops in this assignment. I would greatly appreciate the help! Thank you! Write a program that allows the user to play a guessing game. The game will choose a "secret number", a positive integer less than 10000. The user has 10 tries to guess the number. Requirements: we would have the program select a random number as the "secret number". However, for the purpose of testing...

  • For Python-3 I need help with First creating a text file named "items.txt" that has the...

    For Python-3 I need help with First creating a text file named "items.txt" that has the following data in this order: Potatoes Tomatoes Carrots. Write a python program that 1. Puts this as the first line... import os 2. Creates an empty list 3. Defines main() function that performs the tasks listed below when called. 4. Put these two lines at the top of the main function... if os.path.exists("costlist.txt"): os.remove("costlist.txt") Note: This removes the "costlist.txt" file, if it exists. 5....

  • I need to write a paint job estimator program in python. I have most of it...

    I need to write a paint job estimator program in python. I have most of it down but i keep getting errors and I dont know how to fix it or what im doing worng specs: A painting company has determined that for every 350 square feet of wall space, one gallon of paint and six hours of labor are required. The company charges $62.25 per hour for labor. Write a program call paintjobestimator.py that asks the user to enter...

  • In python, Implement a function studentID() which allows the user to enter the 7-digit student ID....

    In python, Implement a function studentID() which allows the user to enter the 7-digit student ID. The program will keep prompting the user for a last name and first name. If the student does not have a student ID on record, the program will then ask for the student ID, and store that information. If the student already has a student ID, the program will display it, and ask for confirmation whether a new studentID should be assigned (and, if...

  • Python Coding: Write a computer program that stores and tracks information about high school students. The...

    Python Coding: Write a computer program that stores and tracks information about high school students. The first piece of information is what grade the student is in. Since this is for high school, the available values are 9, 10, 11, and 12. We also want to track the student’s GPA. Examples of GPAs are 2.2, 2.6, and 4.0. Finally, we want to track the letter grade that the student got on his or her final exam. These values are A,...

  • Intro to Programming and Logic: Python 2, Chapter 8 – Strings (so far have learned the...

    Intro to Programming and Logic: Python 2, Chapter 8 – Strings (so far have learned the way of a program, variables, expressions, statements, functions, interface design, conditional, recursion and iteration) Write a program that takes a string as a parameter. It will analyze the string and return True if it is a valid float number. It will return False if it is not a valid float value. Your function should return True in any of these cases: 0.17, .17, 5.27,...

  • Part 3: Arrows Write a python program that prompts the user for a number of columns,...

    Part 3: Arrows Write a python program that prompts the user for a number of columns, and them prints the pattern as seen below. You cannot assume that the user will supply positive numbers - if they misbehave you should re-prompt them until they do give you a positive number. Note that your program only has to run one time, but multiple runnings of the program are shown below: How many columns? 3 * * * * * How many...

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
ADVERTISEMENT