Advertisement
HBSB

2.14 adding comments

Dec 9th, 2020
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.95 KB | None | 0 0
  1. # this exercise will look at adding commands to the programme
  2. # using the hash key allows the computer to recognise the text as COMMENTS only
  3. # and not to be used in the execution of the programme.
  4. # each new line of comment must be fronted with a # key.
  5. # in Mu it is shown as greyed out text.  In Trinket I think it is green text.
  6. # the first line of code introduces the bot, Marvin.
  7. # the second line asks for the user's name.  
  8. # The programme creates a VARIABLE with the answer.  
  9. print("Hello there.  My name is Marvin and I'm your personal bot.")
  10. user_name=input("What's your name?")
  11. # the third line of code (line 8) instructs the computer to print a welcome message and include the variable called user_name
  12. print("Hello " + user_name + " and welcome.")
  13. #the fourth line of code is asking the user to give the computer an instruction that it can only respond to if it has an appropriate command
  14. command = input("How can I help? >")
  15. # and from now on the computer is responding to if elif else commands
  16. if command == "add" or command == "plus":
  17.     print("Let's add some numbers.")
  18.     input1=input("Number1 > ")
  19.     input2=input("Number2 > ")
  20.     number1=int(input1)
  21.     number2=int(input2)
  22.     result=number1+number2
  23.     output=str(result)
  24.     print(input1 + "+" + input2 + "=" + output)
  25. elif command == "subtract" or command == "take away":
  26.         print("Let's subtract some numbers.")
  27.         input1=input("Number1")
  28.         input2=input("Number2")
  29.         number1=int(input1)
  30.         number2=int(input2)
  31.         result=number1-number2
  32.         output=str(result)
  33.         print(input1 + "-" + input2 + "=" + output)
  34. # the next line of code instructs the bot to tell the user that it doesn't
  35. # recognise either of the input answers and to let the user know this then
  36. # close the conversation
  37. else:
  38.         print("Sorry I don't understand.  Bye.")
  39. # and the last line is a sign off from the bot        
  40. print ("If that's all, I'll say goodnight.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement