MstrSparks

FL Week 2

Oct 24th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.57 KB | None | 0 0
  1. # FutureLearn Week 1 and 2 Bot
  2. # import the maths module to use Pi
  3. import math
  4.  
  5. # The Bot introduces itself and waits for instructions
  6. print("Hi, I am Marvin, your personal bot.")
  7. print("Let's get started....")
  8. users_name = input("Please enter your name: ")
  9.  
  10. # Marvin welcomes the user
  11. print("Welcome " + users_name + "!")
  12.  
  13. # Marvin wants to play with maths.
  14. # The following allows the user to enter two values to be added together
  15. print("I can be your maths bot.")
  16. print("lets add some numbers")
  17. input1 = int(input("Number 1 >"))
  18. input2 = int(input("Number 2 >"))
  19. result = input1 + input2
  20.  
  21. # The following line uses the str.format() formatting style
  22. # This does not require the data types to be cast
  23. print("The addition of {} + {} gives {}".format(input1, input2, result))
  24.  
  25. # Using str.format() combined with an inline calculation
  26. # The third value used in the str is the result of the subtraction calculation
  27. print("Subtracting the value {} from {} gives a result of {}".format(input1, input2, input2 - input1))
  28.  
  29. print("Lets calculate the area of a square.")
  30. side_of_a_square = float(input("Please enter the length of an edge of your square:"))
  31. print("The area of the square with a side length of {} is {}\n"
  32.       "If you want it as a cube the volume would be {}"
  33.       .format(side_of_a_square, side_of_a_square*side_of_a_square, side_of_a_square**3))
  34.  
  35. # creating a menu and then carrying out the task selected.
  36. print("How about you tell me what you would like to do?")
  37. print("Please select from the following:\n"
  38.       "1) Identify if a number is even or odd.\n"
  39.       "2) Work out the area of a circle.\n")
  40. choice = input()
  41.  
  42. confirmation = input("You selcted option {}. Was that the correct choice? enter 'Y' or 'N'.".format(choice)).upper()
  43.  
  44. # Nested ifs
  45. if confirmation == "Y":
  46.     if choice == "1":
  47.         number = int(input("Please enter a number for me to confirm if it is odd or even:"))
  48.         if number%2 == 0:
  49.             print("Yes! {} is an even number. :)".format(number))
  50.         else:
  51.             print("Sorry! {} is not an even number.".format(number))
  52.  
  53.     elif choice == "2":
  54.         print("Please enter the radius of the circle: ")
  55.         radius = float(input())
  56.         area_of_circle = math.pi * (radius**2)
  57.         print("The area of the circle with radius {} is {}.".format(radius, area_of_circle))
  58.  
  59.     else:
  60.         print("Sorry your choice was not valid. I have not learnt that skill yet.")
  61.  
  62. elif confirmation == "N":
  63.     print("Why oh why do you let me down like this? :(")
  64.  
  65. else:
  66.     print("Sorry you did not enter 'Y' or 'N'.")
Advertisement
Add Comment
Please, Sign In to add comment