Lecture
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
ifandelifstatements 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'."
Lessons in this chapter · Case-specific prompt engineering and techniques for writing prompts specialized in coding
- 1. Zero Shot Prompting (Asking without Examples)
- 2. Few Shot Prompting with Examples
- 3. A Journey of a Thousand Miles Begins with a Single Step - Chain of Thought Prompting
- 4. Enhancing Responses with Generated Knowledge Prompting
- 5. Get Smarter with Role Prompts
- 6. Fill-in-the-blank quiz
- 7. Prompting for Python Code Generation
- 8. Writing Prompts for Debugging Python Code
- 9. Characteristics of Good Code and How to Improve Python Code
- 10. Coding Quiz - Basic Arithmetic Calculator
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help