Simple Program In Python
Table of Contents • • • • • • • • • • Python Calculator In this quick post, we will see how we can create a very simple python calculator program. We will take input from the user about the operation he wants to perform and show the result on its basis. Let’s get started with our python calculator code right away. Modular Code To keep things modular, we will define functions to perform various operations. Here are the operations our calculator will support for: • Addition • Subtraction • Multiplication • Division • Raising a power to number Addition Let’s do our first operation of Addition here. Copy if choice == '1': print(num1, '+',num2, '=', addition(num1, num2)); elif choice == '2': print(num1, '-', num2, '=', subtraction(num1, num2)); elif choice == '3': print(num1, '*', num2, '=', multiplication(num1, num2)); elif choice == '4': print(num1, '/', num2, '=', division(num1, num2)); elif choice == '5': print(num1, '**', num2, '=', raisePower(num1, num2)); else: print('Please select a valid input.'
Sample Program In Python
Python Basics
To create your Hello World! Program, follow these steps: Open your Start menu and choose Python (command line). You should get a prompt that looks like >>. At the prompt, type the following. Use a single quote at the start and the end — it’s beside. Press the Enter key. Python runs the code. Please note that these examples are written in Python 2, and may need some adjustment to run under Python 3. 1 line: Output. Print 'Hello, world!' # This program adds up integers in the command line import sys try: total = sum(int(arg) for arg in sys.argv[1:]).