Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Write your code here :-)
- print('I am ALICE your personal bot')
- user_name = input('What is your name: ')
- print('How can I help you today ' + user_name + '?')
- print()
- operation = input ('Would you like to add, subtract, divide, multiply or average some numbers today? ')
- print()
- # Checks what type of operation has been chosen.
- if operation == 'add' or operation == '+':
- print('You have chosen to add the numbers')
- number1 = int(input ('What is your first number?: '))
- number2 = int(input ('What is your second number?: '))
- result = number1 + number2
- print('Your answer is ' + str(result))
- elif operation == 'subtract' or operation == '-':
- print('You have chosen to add the subtract')
- number1 = int(input ('What is your first number?: '))
- number2 = int(input ('What is your second number?: '))
- result = number1 - number2
- print('Your answer is ' + str(result))
- elif operation == 'divide' or operation == '/':
- print('You have chosen to divide the numbers')
- number1 = int(input ('What is your first number?: '))
- number2 = int(input ('What is your second number?: '))
- result = number1/number2
- print('Your answer is ' + str(result))
- elif operation == 'multiply' or operation == 'x' or operation == '*':
- print('You have chosen to multiply the numbers')
- number1 = int(input ('What is your first number?: '))
- number2 = int(input ('What is your second number?: '))
- result = number1 * number2
- print('Your answer is ' + str(result))
- elif operation == 'average':
- print('Let me average some number for you')
- how_many = int(input('How many numbers do you want me to average: '))
- #Takes an input and casts it to a interger / number
- total = 0
- for number_count in range(how_many):
- number = input('Enter number ' + str(number_count) + ': ')
- total = total + int(number)
- # Asks for the number of each item, adding it to the total.
- result = total / how_many
- print('The average is ' + str(result))
- # prints the result
- elif operation == 'shopping':
- print('Let me take down your shopping list for you.')
- shopping_list = []
- #set up list
- how_many = int(input('How many items do you want to add to your list? '))
- #ask how many items to add
- for item_number in range(how_many):
- item = input('What item would you like to add to the list? ' )
- shopping_list.append(item)
- #add items one at a time to the list
- print()
- print('This is what is on your shopping list: ')
- for item in shopping_list:
- print(item)
- print()
- print('You have '+ str(len(shopping_list)) + ' items on your list')
- #print out the list
- elif operation == 'discount':
- print('Let me work out how much discount you get')
- discount = int(input('What is the discount? '))
- price = float(input('How much is the item? '))
- #coverts to a float incase of decimals...
- print('You want to know how much ' + str(discount) + '% discount off £' + str(price) +' is.')
- print()
- reduced_price = round(price*(discount/100),2)
- #rounds % discount to 2dp.
- print('Your discount is £' + str(reduced_price) + '.')
- print('Your item will now cost £' + str(round(price-reduced_price,2)) + '!')
- else:
- print('I dont understand!')
- print()
- print('Till next time ' + user_name)
Add Comment
Please, Sign In to add comment