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
I have to write this in Python and it must run in Python 3. The last...
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. *** 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. 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 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 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 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. 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 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 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, 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...