• Home
    • About Us
      • Contact
    • 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 Excel Expert
          • Analyzing Data with Microsoft Power BI
          • GDPR DPO
          • Social Media
          • Six Sigma: Total Quality Applications
          • Professional Scrum Master I
          • Accredited Diplomas

          • IT and Computing
          • Sales and Marketing
          • Human Resource
          • Business Management
          • Leadership and Team Working
          • E-Learning

          • Online courses
    • Training Calendar
    • Resources
      • Blog
      • Free Courses
    • Company Training
    • Career
      • IT Jobs
      • Are you linked-in?
      • Career Service
    • Erasmus
    Have any question?

    70008828
    academy@scp.ac.cy
    Login
    SCP Academy
      • Home
      • About Us
        • Contact
      • 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 Excel Expert
            • Analyzing Data with Microsoft Power BI
            • GDPR DPO
            • Social Media
            • Six Sigma: Total Quality Applications
            • Professional Scrum Master I
            • Accredited Diplomas

            • IT and Computing
            • Sales and Marketing
            • Human Resource
            • Business Management
            • Leadership and Team Working
            • E-Learning

            • Online courses
      • Training Calendar
      • Resources
        • Blog
        • Free Courses
      • Company Training
      • Career
        • IT Jobs
        • Are you linked-in?
        • Career Service
      • Erasmus

      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

      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
      Is Microsoft Azure Training Cyprus Worth It?
      5 March, 2022

      Do you want to become an Azure expert and make better use of the tools Microsoft Azure offers? Our Microsoft Azure training Cyprus can help you get there. Cloud computing …

      Introduction to Cybersecurity

      Introduction to Cybersecurity

      Free
      CCNA Routing & Switching V7.0

      CCNA Routing & Switching V7.0

      Free
      350-401 ENCOR Implementing and Operating Cisco Enterprise Network Core Technologies

      350-401 ENCOR Implementing and Operating Cisco Enterprise Network Core Technologies

      €930.00

      Designed by SCP Academy.

      Login with your site account

      No apps configured. Please contact your administrator.

      Lost your password?