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

Input / Output

The document provides a series of Python programming examples covering various fundamental concepts such as input/output, data types, operators, conditional statements, loops, strings, lists, tuples, dictionaries, functions, file handling, and modules. Each section includes code snippets demonstrating the respective concepts. This serves as a basic guide for beginners to understand essential programming constructs in Python.

Uploaded by

volty764
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)
4 views12 pages

Input / Output

The document provides a series of Python programming examples covering various fundamental concepts such as input/output, data types, operators, conditional statements, loops, strings, lists, tuples, dictionaries, functions, file handling, and modules. Each section includes code snippets demonstrating the respective concepts. This serves as a basic guide for beginners to understand essential programming constructs in Python.

Uploaded by

volty764
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

Input / Output

# Input and Output Program


name = input("Enter your name: ")
age = int(input("Enter your age: "))
print("Name:", name)
print("Age:", age)
Data Types
# Data Types Program
a = 10 # int
b = 3.14 # float
c = "Python" # string
d = True # boolean

print(type(a))
print(type(b))
print(type(c))
print(type(d))
Operators
# Operators Program
x = 10
y = 3

print(x + y)
print(x - y)
print(x * y)
print(x / y)
print(x % y)
Conditional Statements
# Conditional Statements Program
num = int(input("Enter a number: "))

if num > 0:
print("Positive")
elif num < 0:
print("Negative")
else:
print("Zero")
Loops
# Loops Program
for i in range(1, 6):
print(i)

i = 1
while i <= 5:
print(i)
i += 1
Strings
# Strings Program
text = "Hello Python"
print([Link]())
print([Link]())
print(text[0:5])
print(len(text))
Lists
# Lists Program
numbers = [1, 2, 3, 4, 5]
[Link](6)
[Link](3)

for n in numbers:
print(n)
Tuples
# Tuples Program
t = (10, 20, 30)
print(t[0])
print(len(t))
Dictionaries
# Dictionaries Program
student = {
"name": "Alice",
"age": 20,
"course": "CS"
}

print(student["name"])
print([Link]())
print([Link]())
Functions
# Functions Program
def add(a, b):
return a + b

result = add(5, 3)
print("Sum:", result)
File Handling
# File Handling Program
file = open("[Link]", "w")
[Link]("Hello File")
[Link]()

file = open("[Link]", "r")


print([Link]())
[Link]()
Modules
# Modules Program
import math

print([Link](16))
print([Link](5))

You might also like