0% found this document useful (0 votes)
2 views2 pages

Basic Python Codes For Beginners

This document provides basic Python code examples for beginners, covering fundamental concepts such as printing messages, performing arithmetic operations, user input, and control flow. It includes examples for checking even or odd numbers, finding the largest of two numbers, and implementing a simple calculator. Additionally, it demonstrates using loops and functions in Python.

Uploaded by

beboansh2012
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Basic Python Codes For Beginners

This document provides basic Python code examples for beginners, covering fundamental concepts such as printing messages, performing arithmetic operations, user input, and control flow. It includes examples for checking even or odd numbers, finding the largest of two numbers, and implementing a simple calculator. Additionally, it demonstrates using loops and functions in Python.

Uploaded by

beboansh2012
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Basic Python Codes for Beginners

1. Print a Message
print("Hello, World!")

2. Addition of Two Numbers


a = 5
b = 3
sum = a + b
print("Sum:", sum)

3. Input from User


name = input("What is your name? ")
print("Hello,", name)

4. Check Even or Odd


num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even number")
else:
print("Odd number")

5. Find Largest of Two Numbers


a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
if a > b:
print("Largest:", a)
else:
print("Largest:", b)

6. Simple Calculator
a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
print("Addition:", a + b)
print("Subtraction:", a - b)
print("Multiplication:", a * b)
print("Division:", a / b)

7. Print Numbers 1 to 5 using Loop


for i in range(1, 6):
print(i)

8. Find Square of a Number


num = int(input("Enter a number: "))
square = num ** 2
print("Square:", square)

9. Check if Number is Positive, Negative or Zero


num = int(input("Enter a number: "))
if num > 0:
print("Positive")
elif num < 0:
print("Negative")
else:
print("Zero")

10. Using a Function


def greet():
print("Welcome to Python!")

greet()

You might also like