Apply your knowledge to build something amazing!
:information_source: Project Overview
:dart: What You'll Build: A scientific calculator that performs trigonometric calculations!
⭐ Difficulty Level: ⭐⭐⭐ (3 out of 5 stars)
⏱️ Estimated Time: 45-60 minutes
:wrench: Skills Practiced:
Step 1: Import & Setup → Step 2: Build Calculator Function → Step 3: Add Validation → Success! 🎉
Go to EduBlocks page and login with your Google account: https://app.edublocks.org/login
Everytime you want to start a new project, click on the "Editor" icon. To resume your project, click on the "Projects" icon.
:warning: Important! Make sure you have the habit of saving once in a while to avoid losing progress. Use Ctrl+S (Windows) or Cmd+S (Mac) to save quickly!
In this scientific calculator project we will be focusing on the basic 3 trigonometric functions which are sine (sin), cosine (cos), tangent (tan).
With these 3 functions, build a calculator that allows users to choose which operation to do.
It will then ask for a float number as input to calculate the answer.
:bulb: Real-World Connection
Trigonometric functions are used everywhere! Video game developers use them for character movement, engineers use them for building bridges, and even music producers use them for sound waves! :video_game::emoji::emoji:
One. Import math module.
In EduBlocks, look for the Import block under the Python category. This is like giving your program a special toolkit for mathematical calculations!
2. Create a function called calculate that will handle the user input and perform the calculation. The function should follow these steps:
:bulb: EduBlocks Tip
To create a function in EduBlocks:
- Find the def block in the Functions category
- Name your function "calculate"
- Add all your code blocks inside the function
Here is a code example of how it looks like:
if choice == "sin":
number = float(input("Enter number: "))
result = math.sin(number)
:warning: Common Pitfall The math module in Python uses radians, not degrees! If you enter 90 expecting sin(90°), you'll get a different answer. To use degrees, you'd need to convert:
math.sin(math.radians(90))
Before moving on, test your basic calculator:
Here is an example output if the input choice is invalid:
Here is an example output if the input choice is sine:
For the advanced version of the project, give it a better validation when choosing an operation.
The rule is you have to use an operations list to check if the input exists.
:bulb: Why Lists?
Using a list makes your code more flexible! If you want to add more operations later (like arcsin or arccos), you just add them to the list instead of changing multiple if statements.
operations = ["sin", "cos", "tan"]
One. Check if the entered operation is valid (i.e. one of the supported operations sin, cos, tan).
2. If the entered operation is not valid, print an error message and repeat the process of choosing an operation.
3. If the entered operation is valid, then proceed to do the calculations.
:bulb: EduBlocks Navigation
- Find the while loop in the Loops category
- The for...in loop is also in the Loops category
- Boolean variables can be created using the set variable block with True/False values
- The break block is in the Loops category too!
Test your advanced validation:
"NameError: name 'math' is not defined"
Calculator only runs once
Wrong answers for trigonometric functions
Validation loop never ends
Make sure your Scientific Calculator project includes:
Once you've completed the basic calculator, here are some creative ways to personalize it:
:bulb: Personalization Tip
Start with one small addition at a time. Get it working perfectly before adding the next feature!
When you have completed your "Scientific Calculator" project, submit it using the link below:
Make sure to test your program before submitting to ensure all required elements are working properly!
Note: You need to submit 1 project link for this project - the advanced version which incorporates all the concepts from the basic version.
:tada: Congratulations on building your scientific calculator! You've just created a tool that mathematicians would have loved to have hundreds of years ago!