Advertisement
Guest User

Untitled

a guest
Oct 9th, 2018
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.59 KB | None | 0 0
  1. #This is a text based calculator written for the Unit 5 programming assignment.
  2.  
  3. #Prompting the user for input. Their input will be assigned to the first operand.
  4. #The users unput is cast to the float data type to allow for more presice evaluations.
  5. #This is consistent throughout the entire program.
  6. print("Please enter your first operand")
  7. first_number = float(input())
  8. while first_number == 0:
  9.     print("Please enter a number greater than or less than zero")
  10.     first_number = float(input())
  11.     continue
  12.  
  13. #Prompting the user for input. Their input will be assigned and used
  14. #as the operator.
  15. print("Please enter your operator")
  16. operator = raw_input()
  17. while operator != "*" or "/" or "+" or "-":
  18.     print("Please use /,*,+, or + for your operator")
  19.     operator = raw_input()
  20.     continue
  21.  
  22. #Prompting the user for input. Their input will be assigned to the second operand
  23. print("Please enter your second operand")
  24. second_number = float(input())
  25. while second_number == 0:
  26.     print("Please enter a number greater than or less than zero")
  27.     second_number = float(input())
  28.     continue
  29.  
  30. #This function utilizes the operand variable to elect which variant of
  31. #expression will be evaluated.
  32. def evaluation(a, b):
  33.     if operator == "*":
  34.         calculaton = a * b
  35.     elif operator == "/":
  36.         calculaton = a / b
  37.     elif operator == "+":
  38.         calculaton = a + b
  39.     else:
  40.         calculaton = a - b
  41.  
  42.     print("Your soluton is: " + str(calculaton))
  43.  
  44. #Calling the evaluation function on the users defined variables to print a solution.
  45. evaluation(first_number, second_number)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement