0% found this document useful (0 votes)
23 views3 pages

Class11 Python Programs Colored

The document contains a series of Python programming examples demonstrating basic concepts such as printing, arithmetic operations, conditional statements, loops, string manipulation, list and dictionary usage, function definition, and file handling. Each program is presented in a code format with expected outputs. These examples serve as a practical introduction to fundamental programming techniques in Python.

Uploaded by

jha28085
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)
23 views3 pages

Class11 Python Programs Colored

The document contains a series of Python programming examples demonstrating basic concepts such as printing, arithmetic operations, conditional statements, loops, string manipulation, list and dictionary usage, function definition, and file handling. Each program is presented in a code format with expected outputs. These examples serve as a practical introduction to fundamental programming techniques in Python.

Uploaded by

jha28085
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
You are on page 1/ 3

Program 1: Hello World

>>> print("Hello, World!")


Hello, World!

Program 2: Simple Addition


>>> a = 5
>>> b = 3
>>> print(a + b)
8

Program 3: If-Else Example


>>> num = 10
>>> if num % 2 == 0:
... print("Even")
... else:
... print("Odd")
Even

Program 4: While Loop


>>> i = 1
>>> while i <= 5:
... print(i)
... i += 1
1
2
3
4
5

Program 5: For Loop with Range


>>> for i in range(1,6):
... print(i)
1
2
3
4
5

Program 6: Factorial (Loop)


>>> n = 5
>>> fact = 1
>>> for i in range(1,n+1):
... fact *= i
>>> print(fact)
120

Program 7: String Slicing


>>> s = "Python"
>>> print(s[0:3])
Pyt

Program 8: String Functions


>>> s = "hello"
>>> print(s.upper())
HELLO

Program 9: List Example


>>> nums = [1,2,3,4]
>>> print(nums[2])
3

Program 10: List Iteration


>>> for x in [10,20,30]:
... print(x)
10
20
30

Program 11: Dictionary Example


>>> d = {"a":1,"b":2}
>>> print(d["b"])
2

Program 12: Function Example


>>> def square(x):
... return x*x
>>> print(square(5))
25

Program 13: Sum of N Natural Numbers


>>> n = 5
>>> total = n*(n+1)//2
>>> print(total)
15

Program 14: Fibonacci Sequence


>>> a,b = 0,1
>>> for i in range(5):
... print(a)
... a,b = b,a+b
0
1
1
2
3

Program 15: File Write & Read


>>> f = open("test.txt","w")
>>> f.write("Hello File")
11
>>> f.close()
>>> f = open("test.txt")
>>> print(f.read())
Hello File

You might also like