# -----------------------------------------------------------------------
# Arithmetic operators #1
# -----------------------------------------------------------------------
# Get the user to input a number
user_input = int(input("Enter a number: "))
# if the remainder of the number divided by 2 is 0, the number is even
if user_input % 2 == 0:
print("The number is even.")
else:
print("The number is odd.")
# -----------------------------------------------------------------------
# Arithmetic operators #2
# -----------------------------------------------------------------------
# Get the radius from the user
radius = float(input("Enter the radius of the circle: "))
# Calculate the area of the circle
area = 3.14159 * radius ** 2
# Display the calculated area
print("The area of the circle with radius",radius,"is",area)
# ------------------------------------------------------------------------
# Arithmetic operators #3
# ------------------------------------------------------------------------
# Set the score to 0
score = 0
# Loop 5 times
for x in range(5):
num1 = int(input("Enter the first number: "))
operator = input("Enter the operator (+, -, *): ")
num2 = int(input("Enter the second number: "))
user_answer = int(input("What is "+str(num1)+str(operator)+str(num2)+"? "))
# Check the answer and update the score
if operator == '+':
correct_answer = num1 + num2
elif operator == '-':
correct_answer = num1 - num2
elif operator == '*':
correct_answer = num1 * num2
if user_answer == correct_answer:
score = score + 1
else:
print("Sorry that's incorrect.")
print("Your score is:", score)
|