Advertisement
Fahim999

Untitled

Dec 4th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.67 KB | None | 0 0
  1. def do_calculation():
  2.     print('Lets',command,'some numbers')
  3.     input1=input('Number 1 :> ')
  4.     print('')
  5.     input2=input('Number 2 :> ')
  6.     numba1=int(input1)
  7.     numba2=int(input2)
  8.     if command == 'Add' or command == 'add':
  9.         result=numba1+numba2
  10.         operator='+'
  11.     elif command == 'Subtract' or command == 'subtract':
  12.         result=numba1-numba2
  13.         operator='-'
  14.     elif command == 'Multiply' or command == 'multiply':
  15.         result=numba1*numba2
  16.         operator='*'
  17.     elif command == 'Divide' or command == 'divide':
  18.         result=numba1/numba2
  19.         operator='/'
  20.     elif command == 'Power' or command == 'power':
  21.         result=numba1**numba2
  22.         operator='**'
  23.     ansa=str(result)
  24.     print(' ')
  25.     print(numba1,operator,numba2,'=',ansa)
  26.    
  27. def do_average_or_total():
  28.     print('Lets find the',command,'of some numbers')
  29.     print(' ')
  30.     how_many = input('How many numbers? ')
  31.     how_many = int(how_many)
  32.     total = 0
  33.     for counter in range(how_many):
  34.         number = input('Enter number ' + str(counter+1) + '> ')
  35.         total = total + int(number)
  36.     result = total / how_many
  37.     print(' ')
  38.     if command == 'Total' or command == 'total':
  39.         print('The total is',total)
  40.     elif command == 'Average' or command == 'average':
  41.         print('The average is',result)
  42.     else:
  43.         print('Error!')
  44.  
  45. print('****************************************')
  46. print('********                        ********')
  47. print('********   WELCOME TO THE BOT   ********')
  48. print('********                        ********')
  49. print('******  MASTER PROGRAMMER: FAHIM  ******')
  50. print('********                        ********')
  51. print('****************************************')
  52.  
  53. print('Hi, I am the Bot')
  54. print('')
  55.  
  56. #   Asks the user to enter their name
  57. user_name=input("What's you name? :>")
  58. print('Welcome '+user_name+'!')
  59. print('')
  60.  
  61. finished = False
  62. while finished == False:
  63.     command=input("What is your command?:> ")
  64.     if command == 'Add' or command == 'add':
  65.         do_calculation()
  66.     elif command == 'Subtract' or command == 'subtract':
  67.         do_calculation()
  68.     elif command == 'Multiply' or command == 'multiply':
  69.         do_calculation()
  70.     elif command == 'Divide' or command == 'divide':
  71.         do_calculation()
  72.     elif command == 'Total' or command == 'total':
  73.         do_average_or_total()
  74.     elif command == 'Average' or command == 'average':
  75.         do_average_or_total()
  76.     if command == 'Power' or command == 'power':
  77.         do_calculation()
  78.     elif command == 'bye' or command == 'Bye':
  79.         finished = True
  80.         print('Goodbye')
  81.     else:
  82.         print("Sorry! I don't get it!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement