Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # FutureLearn Week 1 and 2 Bot
- # import the maths module to use Pi
- import math
- # The Bot introduces itself and waits for instructions
- print("Hi, I am Marvin, your personal bot.")
- print("Let's get started....")
- users_name = input("Please enter your name: ")
- # Marvin welcomes the user
- print("Welcome " + users_name + "!")
- # Marvin wants to play with maths.
- # The following allows the user to enter two values to be added together
- print("I can be your maths bot.")
- print("lets add some numbers")
- input1 = int(input("Number 1 >"))
- input2 = int(input("Number 2 >"))
- result = input1 + input2
- # The following line uses the str.format() formatting style
- # This does not require the data types to be cast
- print("The addition of {} + {} gives {}".format(input1, input2, result))
- # Using str.format() combined with an inline calculation
- # The third value used in the str is the result of the subtraction calculation
- print("Subtracting the value {} from {} gives a result of {}".format(input1, input2, input2 - input1))
- print("Lets calculate the area of a square.")
- side_of_a_square = float(input("Please enter the length of an edge of your square:"))
- print("The area of the square with a side length of {} is {}\n"
- "If you want it as a cube the volume would be {}"
- .format(side_of_a_square, side_of_a_square*side_of_a_square, side_of_a_square**3))
- # creating a menu and then carrying out the task selected.
- print("How about you tell me what you would like to do?")
- print("Please select from the following:\n"
- "1) Identify if a number is even or odd.\n"
- "2) Work out the area of a circle.\n")
- choice = input()
- confirmation = input("You selcted option {}. Was that the correct choice? enter 'Y' or 'N'.".format(choice)).upper()
- # Nested ifs
- if confirmation == "Y":
- if choice == "1":
- number = int(input("Please enter a number for me to confirm if it is odd or even:"))
- if number%2 == 0:
- print("Yes! {} is an even number. :)".format(number))
- else:
- print("Sorry! {} is not an even number.".format(number))
- elif choice == "2":
- print("Please enter the radius of the circle: ")
- radius = float(input())
- area_of_circle = math.pi * (radius**2)
- print("The area of the circle with radius {} is {}.".format(radius, area_of_circle))
- else:
- print("Sorry your choice was not valid. I have not learnt that skill yet.")
- elif confirmation == "N":
- print("Why oh why do you let me down like this? :(")
- else:
- print("Sorry you did not enter 'Y' or 'N'.")
Advertisement
Add Comment
Please, Sign In to add comment