Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #This is a text based calculator written for the Unit 5 programming assignment.
- #Prompting the user for input. Their input will be assigned to the first operand.
- #The users unput is cast to the float data type to allow for more presice evaluations.
- #This is consistent throughout the entire program.
- print("Please enter your first operand")
- first_number = float(input())
- while first_number == 0:
- print("Please enter a number greater than or less than zero")
- first_number = float(input())
- continue
- #Prompting the user for input. Their input will be assigned and used
- #as the operator.
- print("Please enter your operator")
- operator = raw_input()
- while operator != "*" or "/" or "+" or "-":
- print("Please use /,*,+, or + for your operator")
- operator = raw_input()
- continue
- #Prompting the user for input. Their input will be assigned to the second operand
- print("Please enter your second operand")
- second_number = float(input())
- while second_number == 0:
- print("Please enter a number greater than or less than zero")
- second_number = float(input())
- continue
- #This function utilizes the operand variable to elect which variant of
- #expression will be evaluated.
- def evaluation(a, b):
- if operator == "*":
- calculaton = a * b
- elif operator == "/":
- calculaton = a / b
- elif operator == "+":
- calculaton = a + b
- else:
- calculaton = a - b
- print("Your soluton is: " + str(calculaton))
- #Calling the evaluation function on the users defined variables to print a solution.
- evaluation(first_number, second_number)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement