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

Python Basics: Simple Programs Guide

The document contains a series of Python programs demonstrating basic programming concepts. These include printing messages, performing arithmetic operations, taking user input, determining even or odd numbers, finding the largest of two numbers, printing a range of numbers, calculating the sum of the first n numbers, and defining a simple function. Each program is designed to illustrate fundamental programming techniques and user interaction.

Uploaded by

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

Python Basics: Simple Programs Guide

The document contains a series of Python programs demonstrating basic programming concepts. These include printing messages, performing arithmetic operations, taking user input, determining even or odd numbers, finding the largest of two numbers, printing a range of numbers, calculating the sum of the first n numbers, and defining a simple function. Each program is designed to illustrate fundamental programming techniques and user interaction.

Uploaded by

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

Program 1: Print message

print("Welcome to Python Lab")

Program 2: Add two numbers


a=5
b=7
print("Sum =", a + b)

Program 3: User input & display


name = input("Enter your name: ")
age = input("Enter your age: ")
print("Name:", name)
print("Age:", age)

Program 4: Even or Odd


num = int(input("Enter a number: "))

if num % 2 == 0:
print("Even number")
else:
print("Odd number")

Program 5: Largest of two numbers


a = int(input("Enter first number: "))
b = int(input("Enter second number: "))

if a > b:
print("A is greater")
else:
print("B is greater")

Program 6: Print numbers from 1 to 5


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

Program 7: Sum of first n numbers


n = int(input("Enter n: "))
sum = 0

for i in range(1, n + 1):


sum = sum + i

print("Sum =", sum)

Program 8: Simple function


def add(a, b):
return a + b

print(add(3, 4))

You might also like