Writing a Simple Program (in Python)
In this section, we explore how to write simple programs using Python, focusing specifically on two practical examples: adding two numbers and checking if a number is even or odd.
Example 1: Add Two Numbers
This program demonstrates how to take input from the user, perform a basic arithmetic operation (addition), and then output the result. The program uses the input()
function to prompt the user for two numbers, converts those inputs to integers, adds them together, and prints the sum.
Code Implementation:
Code Editor - python
Example 2: Check Even or Odd
The second example illustrates the use of conditional statements in coding. The program checks if the user-provided number is even or odd by using the modulo operator. If the remainder when divided by 2 is zero, it prints 'Even'; otherwise, it prints 'Odd'.
Code Implementation:
Code Editor - python
These examples showcase the fundamental concepts of inputs and outputs in programming and introduce beginners to basic code structure in Python.