Advertisement
Aequitas35

personal_bot

Oct 18th, 2018
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.28 KB | None | 0 0
  1. def char_checker(a):
  2.     if a.isdigit() == False or not a:
  3.         return False
  4.     else:
  5.         return True
  6.  
  7. def zero_checker(a):
  8.     if int(a) == 0:
  9.         return False
  10.     else:
  11.         return True
  12.  
  13. def do_calculation():
  14.     while True:
  15.         num1 = input("Enter first number: ")
  16.         num2 = input("Enter second number: ")
  17.         if opr == "add" or opr == "Add" or opr == "+":
  18.             if char_checker(num1) == False or char_checker(num2) == False:
  19.                 print("Not acceptable! Enter again")
  20.                 continue
  21.             else:
  22.                 result = int(num1) + int(num2)
  23.                 output = str(result)
  24.         elif opr == "substract" or opr == "Substract" or opr == "-":
  25.             if char_checker(num1) == False or char_checker(num2) == False:
  26.                 print("Not acceptable! Enter again")
  27.                 continue
  28.             else:
  29.                 result = int(num1) - int(num2)
  30.                 output = str(result)
  31.         elif opr == "multiply" or opr == "Multiply" or opr == "*":
  32.             if char_checker(num1) == False or char_checker(num2) == False:
  33.                 print("Not acceptable! Enter again")
  34.                 continue
  35.             else:
  36.                 result = int(num1) * int(num2)
  37.                 output = str(result)
  38.         elif opr == "divide" or opr == "Divide" or opr == "/":
  39.             if char_checker(num1) == False or zero_checker(num2) == False or char_checker(num2) == False:
  40.                 print("Not acceptable! Enter again")
  41.                 continue
  42.             else:
  43.                 result = int(num1) / int(num2)
  44.                 output = str(result)
  45.         if opr == "add" or opr == "Add" or opr == "+":
  46.             print(num1 + "+" + num2 + "=" + output)
  47.             break
  48.         elif opr == "substract" or opr == "Substract" or opr == "-":
  49.             print(num1 + "-" + num2 + "=" + output)
  50.             break
  51.         elif opr == "multiply" or opr == "Multiply" or opr == "*":
  52.             print(num1 + "*" + num2 + "=" + output)
  53.             break
  54.         elif opr == "divide" or opr == "Divide" or opr == "/":
  55.             print(num1 + "/" + num2 + "=" + output)
  56.             break
  57.  
  58. print("Hi, I'm Marvin, your personal assistant.")
  59. your_name = input("What's your name?\n")
  60. print("Welcome " + your_name + "!")
  61. while True:
  62.     print()
  63.     opr = input("I can add[+], substract[-], multiply[*], divide[/] and [a]verage calculations and [s]hopping list generation.\nWhich one do you need?\n")
  64.     if opr == "add" or opr =="+" or opr == "substract" or opr == "-" or opr == "multiply" or opr == "*" or opr == "divide" or opr == "/":
  65.         do_calculation()
  66.         continue
  67.    
  68.     while True:
  69.         if opr == "a" or opr == "A":
  70.             how_many = input("How many numbers do you want to calculate?\n")
  71.             total = 0
  72.             for number_count in range(int(how_many)):
  73.                 number = input("Enter number " + str(number_count) + ": ")
  74.                 total = total + int(number)
  75.             avr = total/int(how_many)
  76.             print()
  77.             print("The average of the " + how_many + " numbers you entered is: " + str(avr))
  78.             break
  79.         elif opr == "s" or opr == "S":
  80.             how_many = input("How many items do you want to buy? : ")
  81.             shopping = []
  82.             total = 0
  83.             for item_count in range(int(how_many)):
  84.                 item = input("What is the item " + str(item_count) + " you want? : ")
  85.                 price = float(input("What is the price for this item? : "))
  86.                 shopping.append(item)
  87.                 total = total + price
  88.             print()
  89.             for item in shopping:
  90.                 print(item)
  91.             if int(how_many) > 1:
  92.                 print()
  93.                 print("You have " + str(len(shopping)) + " items in your shopping list.\nTotal price of these items are " + str(total) + " $")
  94.                 break
  95.             else:
  96.                 print()
  97.                 print("You have " + str(len(shopping)) + " item in your shopping list.\nTotal price of these items are " + str(total) + " $")
  98.                 break
  99.         else:
  100.             print()
  101.             print("I'm not capable of doing " + opr + " at the moment. You should keep upgrading me.")
  102.             break
  103.     continue
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement