Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Ask user for name and greet them.
- print("Hello, World!")
- users_name = input("Name: ")
- print("Hello, " + users_name + ".")
- # Ask user to input command to add or subtract.
- command = input("operation?")
- # Get two integers from user and add.
- if command == "add" or command == "addition":
- num1 = input("Number 1: ")
- n1 = int(num1)
- num2 = input("Number 2: ")
- n2 = int(num2)
- result = n1 + n2
- output = str(result)
- print(num1 + " + " + num2 + " = " + output)
- # Get two integers from user and subtract.
- elif command == "sub" or command == "subtract" or command == "subtraction":
- num1 = input("Number 1: ")
- n1 = int(num1)
- num2 = input("Number 2: ")
- n2 = int(num2)
- result = n1 - n2
- output = str(result)
- print(num1 + " - " + num2 + " = " + output)
- # Get two integers from user and multiply.
- elif command == "multiply" or command == "multiplication":
- num1 = input("Number 1: ")
- n1 = int(num1)
- num2 = input("Number 2: ")
- n2 = int(num2)
- result = n1 * n2
- output = str(result)
- print(num1 + " * " + num2 + " = " + output)
- # Get two integers from user and divide.
- elif command == "divide" or command == "division":
- num1 = input("Number 1: ")
- n1 = int(num1)
- num2 = input("Number 2: ")
- n2 = int(num2)
- result = n1 / n2
- output = str(result)
- print(num1 + " / " + num2 + " = " + output)
- # Get dimensions and calculate area.
- elif command == "Area" or command == "area":
- num1 = input("Length: ")
- n1 = int(num1)
- num2 = input("Width: ")
- n2 = int(num2)
- result = n1 * n2
- output = str(result)
- print(num1 + " * " + num2 + " = " + output)
- # Get dimensions from user and calculate volume.
- elif command == "Volume" or command == "volume":
- num1 = input("Length: ")
- n1 = int(num1)
- num2 = input("Width: ")
- n2 = int(num2)
- num3 = input("Height: ")
- n3 = int(num3)
- result = n1 * n2 * n3
- output = str(result)
- print(num1 + " * " + num2 + " * " + num3 + " = " + output)
- # Calculate average; get a list of numbers and size of list from user, then set total to 0
- elif command == "Average" or command == "mean":
- numbers = []
- size = input("Number of items to average:")
- size = int(size)
- total = 0
- #input number from user and add to total
- for item_n in range(size):
- item = input("what is item " + str(item_n) + "?")
- numbers.append(item)
- value = int(item)
- total += value
- #calculate average by dividing total by list size
- average = (total / size)
- mean = str(average)
- print("The average is " + mean)
- # Calculalate tip based on price paid and desired percentage
- elif command == "tip" or command == "gratuity":
- price = input("Original price:")
- price = int(price)
- percent = input("What percent would you like to tip?")
- percent = (int(percent)/100)
- tip = price * percent
- tip = str(tip)
- print("Tip is " + tip)
- # invalid input
- else:
- print("I don't understand " + "'" + command + "'")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement