• Courses
    • Course Schedule
    • Self-Paced (CPDs)
    • Corporate Training
    • Resources
      • HRDA/Αναδ Process
      • Blog
      • Free Course - Cybersecurity
        • Cybersecurity Course for Beginner Level
        • Cybersecurity Course for Intermediate Level
        • Cybersecurity Course for Advanced Level
      • Career
        • The Career Test
        • Jobs at SCP
        • IT Jobs
        • Are you linked-in?
        • Career Service
    • Erasmus +
      • Erasmus KA2
      • Erasmus News
      • Erasmus Mobilities
        • Erasmus Courses
        • Erasmus+ Full Package
        • Gallery – Erasmus+
      • Apply with us!
    • About Us
      • Contact
    Have any question?

    70008828
    academy@scp.ac.cy
    Login
    SCP Academy
      • Courses
      • Course Schedule
      • Self-Paced (CPDs)
      • Corporate Training
      • Resources
        • HRDA/Αναδ Process
        • Blog
        • Free Course - Cybersecurity
          • Cybersecurity Course for Beginner Level
          • Cybersecurity Course for Intermediate Level
          • Cybersecurity Course for Advanced Level
        • Career
          • The Career Test
          • Jobs at SCP
          • IT Jobs
          • Are you linked-in?
          • Career Service
      • Erasmus +
        • Erasmus KA2
        • Erasmus News
        • Erasmus Mobilities
          • Erasmus Courses
          • Erasmus+ Full Package
          • Gallery – Erasmus+
        • Apply with us!
      • About Us
        • Contact

      Blog

      • Home
      • Blog
      • Python Calculator

      Python Calculator

      • Posted by admin
      • Date July 10, 2019

      Python Program to Make a Simple Calculator

      In this example you will learn to create a simple calculator that can add, subtract, multiply or divide depending upon the input from the user. You can Run the calculator using this online compiler found here

       

      PS: If the code below does not compile please visit this link and copy the code to the compiler directly from there.

       

      1. # Program make a simple calculator that can add, subtract, multiply and divide using functions
      2. # This function adds two numbers
      3. def add(x, y):
      4. return x + y
      5. # This function subtracts two numbers
      6. def subtract(x, y):
      7. return x - y
      8. # This function multiplies two numbers
      9. def multiply(x, y):
      10. return x * y
      11. # This function divides two numbers
      12. def divide(x, y):
      13. return x / y
      14. print("Select operation.")
      15. print("1.Add")
      16. print("2.Subtract")
      17. print("3.Multiply")
      18. print("4.Divide")
      19. # Take input from the user
      20. choice = input("Enter choice(1/2/3/4):")
      21. num1 = int(input("Enter first number: "))
      22. num2 = int(input("Enter second number: "))
      23. if choice == '1':
      24. print(num1,"+",num2,"=", add(num1,num2))
      25. elif choice == '2':
      26. print(num1,"-",num2,"=", subtract(num1,num2))
      27. elif choice == '3':
      28. print(num1,"*",num2,"=", multiply(num1,num2))
      29. elif choice == '4':
      30. print(num1,"/",num2,"=", divide(num1,num2))
      31. else:
      32. print("Invalid input")
      • Share:
      author avatar
      admin

      Next post

      Microsoft Role-based Certification Roadmap
      July 22, 2019

      You may also like

      Mastering IT Recruitment: A Comprehensive Guide for HR Professionals
      11 September, 2024
      As technology continues to evolve, so does the challenge of recruiting skilled IT professionals. HR teams are expected to navigate an increasingly complex landscape of roles, from cloud computing experts …
      Importance of Adopting DORA
      11 July, 2024
      Importance of Adopting DORA Adopting the Digital Operational Resilience Act (DORA) is crucial for financial institutions aiming to maintain high standards in service continuity and resilience. This helps protect data, …
      ChatGPT Prompt Cheat Sheet
      ChatGPT Prompt Cheat Sheet with Examples
      10 January, 2024
      Introduction to Cybersecurity

      Introduction to Cybersecurity

      Free
      CISCO CCNA Routing and Switching

      CISCO CCNA Routing and Switching

      Free
      Microsoft Office 365 – End User

      Microsoft Office 365 – End User

      Free

      Designed by SCP Academy.

      Login with your site account

      No apps configured. Please contact your administrator.
      Lost your password?