Coding Examples

Coding Examples

2 min read Jun 23, 2024
Coding Examples

Coding Examples in Python

Here are some simple coding examples in Python:

Hello World

print("Hello, world!")

This code prints the text "Hello, world!" to the console.

Adding two numbers

num1 = 10
num2 = 5
sum = num1 + num2
print("The sum is:", sum)

This code assigns the values 10 and 5 to the variables num1 and num2, respectively. It then adds them together and stores the result in the variable sum. Finally, it prints the sum to the console.

Finding the largest number

num1 = 15
num2 = 20
num3 = 10

if num1 > num2 and num1 > num3:
  largest = num1
elif num2 > num1 and num2 > num3:
  largest = num2
else:
  largest = num3

print("The largest number is:", largest)

This code compares the three numbers num1, num2, and num3 to find the largest one. It uses an if statement with elif and else clauses to determine the largest number and stores it in the variable largest. Finally, it prints the largest number to the console.

These are just a few simple examples of Python code. Python is a versatile language that can be used for a wide range of tasks, from simple scripting to complex data analysis and machine learning.

Featured Posts