{
}
Online Python Compiler
Online R Compiler
Online SQL Editor
Online HTML/CSS Editor
Online Java Compiler
Online C Compiler
Online C++ Compiler
Online C# Compiler
Online JavaScript Compiler
Online Typescript Compiler
Typescript Online Compiler
Online GoLang Compiler
Online Rust Compiler
Scala Online Compiler
Dart Online Compiler
Ruby Online Compiler
Online PHP Compiler
Online Swift Compiler
Generating Link
Generating Link
Share your code
Share code
Copy Link
Copied to clipboard
or share using
BLACK
NOVEMBER
Ends in
Get 66% off PRO
Ends in
Are you struggling to build your coding confidence or land your first job?
Fast-track to your first pay-check.
Ends in
Start PRO
Start PRO
BLACK
NOVEMBER
Ends in
Get 66% off PRO
Ends in
Are you struggling to build your coding confidence or land your first job?
Fast-track to your first pay-check.
Ends in
Start PRO
Start PRO
Python Online Compiler
Learn Python App
Learn Python
main.py
Output
main.py
Share
Run
Run
import math def calculator(): print("\nBasic Calculator") print("1. Addition") print("2. Subtraction") print("3. Multiplication") print("4. Division") choice = input("Choose an operation (1-4): ") num1 = float(input("Enter first number: ")) num2 = float(input("Enter second number: ")) if choice == "1": print(f"Result: {num1 + num2}") elif choice == "2": print(f"Result: {num1 - num2}") elif choice == "3": print(f"Result: {num1 * num2}") elif choice == "4": if num2 == 0: print("Error: Division by zero") else: print(f"Result: {num1 / num2}") else: print("Invalid choice") def area_perimeter(): print("\nArea & Perimeter Finder") print("1. Circle") print("2. Rectangle") print("3. Square") print("4. Triangle (Perimeter only)") choice = input("Choose a shape (1-4): ") if choice == "1": radius = float(input("Enter radius: ")) area = math.pi * radius**2 perimeter = 2 * math.pi * radius print(f"Area: {area:.2f}, Perimeter: {perimeter:.2f}") elif choice == "2": length = float(input("Enter length: ")) width = float(input("Enter width: ")) area = length * width perimeter = 2 * (length + width) print(f"Area: {area}, Perimeter: {perimeter}") elif choice == "3": side = float(input("Enter side length: ")) area = side**2 perimeter = 4 * side print(f"Area: {area}, Perimeter: {perimeter}") elif choice == "4": a = float(input("Enter first side: ")) b = float(input("Enter second side: ")) c = float(input("Enter third side: ")) perimeter = a + b + c print(f"Perimeter: {perimeter}") else: print("Invalid choice") while True: print("\nMain Menu") print("1. Calculator") print("2. Area & Perimeter Finder") print("3. Exit") option = input("Choose an option (1-3): ") if option == "1": calculator() elif option == "2": area_perimeter() elif option == "3": print("Goodbye!") break else: print("Invalid choice, try again.")
Output
Clear