Create a calculator that takes two numbers and prints their sum, difference, product, and quotient. (Concepts: arithmetic operators +, -, *, /)
Sample Code:
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
print("Sum:", num1 + num2)
print("Difference:", num1 - num2)
print("Product:", num1 * num2)
print("Quotient:", num1 / num2)Alright, students, Day 2 builds on input by adding math! We're making a mini calculator. Start with two input() calls to get numbers from the user. But wait—input() gives strings, so we wrap it in float() to convert to floating-point numbers (decimals). Why float? It handles whole numbers and decimals; if you used int(), it'd crash on decimals like 2.5. Variables num1 and num2 store these.
Now, the math: Python's arithmetic operators are straightforward. + adds, - subtracts, * multiplies (not x!), and / divides (always gives a float result, even if whole numbers). Each print() outputs a label like "Sum:" followed by the comma (which adds a space), then the calculation. Run it: Enter 5 and 2—it prints Sum: 7.0, Difference: 3.0, etc.
Watch out for division by zero—it'll error! In 10-15 minutes, try adding more operations like exponentiation with ** (e.g., num1 ** num2 for power). This reinforces variables and operators. You're doing awesome—math in code is powerful!