Advertisement
jimboulton

jim - week 2-15

Feb 14th, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. print("Hi, I am Jim, your personal bot.")
  2. # ask the user their name
  3. name = input("What is your name? ")
  4. print("Hello " + name)
  5. validip = 0
  6. # what function do you want to do?
  7. command = input("type: add, subtract, multiply, or divide ")
  8. # get the 2 inputs
  9. if command == "add" or command == "subtract" or command == "multiply" or command == "divide":
  10. validip = 1
  11. # print(" valid request")
  12. else:
  13. validip = 0
  14. # print(" invalid request")
  15. if validip == 1:
  16. # get inputs
  17. input1 = input("Number 1 > ")
  18. input2 = input("Number 2 > ")
  19. number1 = int(input1)
  20. number2 = int(input2)
  21. # do - add, subtract, multiply, or divide
  22. if command == "add" or command == "plus":
  23. # print("add numbers")
  24. result = number1 + number2
  25. elif command == "subtract":
  26. # print("subtract numbers")
  27. result = number1 - number2
  28. elif command == "multiply":
  29. # print("multiply numbers")
  30. result = number1 * number2
  31. elif command == "divide":
  32. # print("divide numbers")
  33. result = number1 / number2
  34. if validip == 1:
  35. # print result
  36. output = str(result)
  37. print(input1 + " " + command + " " + input2 + " = " + output)
  38. # not +, -, *, /
  39. else:
  40. print("Invalid function selection")
  41. print("bye")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement