Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def char_checker(a):
- if a.isdigit() == False or not a:
- return False
- else:
- return True
- def zero_checker(a):
- if int(a) == 0:
- return False
- else:
- return True
- def do_calculation():
- while True:
- num1 = input("Enter first number: ")
- num2 = input("Enter second number: ")
- if opr == "add" or opr == "Add" or opr == "+":
- if char_checker(num1) == False or char_checker(num2) == False:
- print("Not acceptable! Enter again")
- continue
- else:
- result = int(num1) + int(num2)
- output = str(result)
- elif opr == "substract" or opr == "Substract" or opr == "-":
- if char_checker(num1) == False or char_checker(num2) == False:
- print("Not acceptable! Enter again")
- continue
- else:
- result = int(num1) - int(num2)
- output = str(result)
- elif opr == "multiply" or opr == "Multiply" or opr == "*":
- if char_checker(num1) == False or char_checker(num2) == False:
- print("Not acceptable! Enter again")
- continue
- else:
- result = int(num1) * int(num2)
- output = str(result)
- elif opr == "divide" or opr == "Divide" or opr == "/":
- if char_checker(num1) == False or zero_checker(num2) == False or char_checker(num2) == False:
- print("Not acceptable! Enter again")
- continue
- else:
- result = int(num1) / int(num2)
- output = str(result)
- if opr == "add" or opr == "Add" or opr == "+":
- print(num1 + "+" + num2 + "=" + output)
- break
- elif opr == "substract" or opr == "Substract" or opr == "-":
- print(num1 + "-" + num2 + "=" + output)
- break
- elif opr == "multiply" or opr == "Multiply" or opr == "*":
- print(num1 + "*" + num2 + "=" + output)
- break
- elif opr == "divide" or opr == "Divide" or opr == "/":
- print(num1 + "/" + num2 + "=" + output)
- break
- print("Hi, I'm Marvin, your personal assistant.")
- your_name = input("What's your name?\n")
- print("Welcome " + your_name + "!")
- while True:
- print()
- opr = input("I can add[+], substract[-], multiply[*], divide[/] and [a]verage calculations and [s]hopping list generation.\nWhich one do you need?\n")
- if opr == "add" or opr =="+" or opr == "substract" or opr == "-" or opr == "multiply" or opr == "*" or opr == "divide" or opr == "/":
- do_calculation()
- continue
- while True:
- if opr == "a" or opr == "A":
- how_many = input("How many numbers do you want to calculate?\n")
- total = 0
- for number_count in range(int(how_many)):
- number = input("Enter number " + str(number_count) + ": ")
- total = total + int(number)
- avr = total/int(how_many)
- print()
- print("The average of the " + how_many + " numbers you entered is: " + str(avr))
- break
- elif opr == "s" or opr == "S":
- how_many = input("How many items do you want to buy? : ")
- shopping = []
- total = 0
- for item_count in range(int(how_many)):
- item = input("What is the item " + str(item_count) + " you want? : ")
- price = float(input("What is the price for this item? : "))
- shopping.append(item)
- total = total + price
- print()
- for item in shopping:
- print(item)
- if int(how_many) > 1:
- print()
- print("You have " + str(len(shopping)) + " items in your shopping list.\nTotal price of these items are " + str(total) + " $")
- break
- else:
- print()
- print("You have " + str(len(shopping)) + " item in your shopping list.\nTotal price of these items are " + str(total) + " $")
- break
- else:
- print()
- print("I'm not capable of doing " + opr + " at the moment. You should keep upgrading me.")
- break
- continue
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement