Coding Quiz
In this coding quiz, you are tasked with writing a function that takes two integers and an operation type as inputs and performs the corresponding arithmetic operation.
Write a program that takes two integers and an operation type from the user and performs the chosen operation (addition, subtraction, multiplication, division) on those numbers.
The operation types are as follows:
-
'a'
: addition -
'b'
: subtraction -
'm'
: multiplication -
'd'
: division
Basic Arithmetic Calculator
def solution(a, b, operation):
return # Write your code here
Hint
- Use
if
andelif
statements to branch according to the input operation type. - Be cautious that the second number is not zero when performing division.
Using what you've learned so far, write a program that takes two integers and an operation type as inputs, performs the corresponding operation, and checks if it passes the test.
Input/Output Examples
- Input:
6, 3, 'a'
- Output:
9
- Input:
10, 5, 'd'
- Output:
2.0
- Input:
7, 2, 'm'
- Output:
14
- Input:
9, 3, 'x'
- Output:
"Invalid operation. Please choose one of 'a', 'b', 'm', 'd'."
Want to learn more?
Join CodeFriends Plus membership or enroll in a course to start your journey.