• Courses
          • IT Training

          • Microsoft
          • Azure
          • Office 365
          • Microsoft Office Specialist
          • Amazon - AWS
          • Linux
          • Cisco
          • Desktop
          • Fortinet
          • MikroTik
          • VoIP
          • CyberSecurity
          • Programming Languages
          • Databases
          • Machine Learning / Analytics
          • Azure
          • GDPR
          • Blockchain and Cryptocurrency
          • PECB
          • HRDA INSTRUCTOR (EEK)
          • Business Training

          • ISO 13053 Six Sigma Methodology Trainings
          • Managing Projects with Microsoft Project Management
          • Microsoft Advanced Excel
          • Analyzing Data with Microsoft Power BI
          • GDPR DPO
          • Social Media
          • Six Sigma: Total Quality Applications
          • Online Courses – Learn Anything, On Your Schedule

          • Top Self Paced Courses
          • Accredited Diplomas

          • IT and Computing
          • Sales and Marketing
          • Human Resource
          • Business Management
          • Leadership and Team Working
    • Upcoming Courses
    • Corporate Training
    • About Us
      • Contact
    • Resources
      • Blog
      • Free Courses
    • Career
      • Jobs at SCP
      • IT Jobs
      • Are you linked-in?
      • Career Service
    • Erasmus +
      • Erasmus KA2
      • Erasmus Mobilities
        • Erasmus Courses
        • Erasmus+ Full Package
        • Gallery – Erasmus+
      • Apply with us!
    Have any question?

    70008828
    academy@scp.ac.cy
    Login
    SCP Academy
      • Courses
            • IT Training

            • Microsoft
            • Azure
            • Office 365
            • Microsoft Office Specialist
            • Amazon - AWS
            • Linux
            • Cisco
            • Desktop
            • Fortinet
            • MikroTik
            • VoIP
            • CyberSecurity
            • Programming Languages
            • Databases
            • Machine Learning / Analytics
            • Azure
            • GDPR
            • Blockchain and Cryptocurrency
            • PECB
            • HRDA INSTRUCTOR (EEK)
            • Business Training

            • ISO 13053 Six Sigma Methodology Trainings
            • Managing Projects with Microsoft Project Management
            • Microsoft Advanced Excel
            • Analyzing Data with Microsoft Power BI
            • GDPR DPO
            • Social Media
            • Six Sigma: Total Quality Applications
            • Online Courses – Learn Anything, On Your Schedule

            • Top Self Paced Courses
            • Accredited Diplomas

            • IT and Computing
            • Sales and Marketing
            • Human Resource
            • Business Management
            • Leadership and Team Working
      • Upcoming Courses
      • Corporate Training
      • About Us
        • Contact
      • Resources
        • Blog
        • Free Courses
      • Career
        • Jobs at SCP
        • IT Jobs
        • Are you linked-in?
        • Career Service
      • Erasmus +
        • Erasmus KA2
        • Erasmus Mobilities
          • Erasmus Courses
          • Erasmus+ Full Package
          • Gallery – Erasmus+
        • Apply with us!

      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

      Cisco Training Cyprus
      Cisco Training Cyprus – Achieving Cisco Routing and Switching Certification
      12 November, 2022
      SCP Academy – for Python Training in Cyprus
      SCP Academy – For Python Training in Cyprus
      6 April, 2022
      MTCNA Training
      Register SCP Academy For MTCNA Training in Cyprus
      25 March, 2022
      Introduction to Cybersecurity

      Introduction to Cybersecurity

      Free
      CCNA Routing & Switching V7.0

      CCNA Routing & Switching V7.0

      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?