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

Class 11 CS Python Programs

The document provides a basic overview of fundamental programming concepts including input/output, data types, operators, conditional statements, loops, strings, lists, tuples, dictionaries, functions, file handling, and modules. Each section includes simple code examples demonstrating the respective concepts. The content is aimed at beginners learning programming basics.

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)
2 views12 pages

Class 11 CS Python Programs

The document provides a basic overview of fundamental programming concepts including input/output, data types, operators, conditional statements, loops, strings, lists, tuples, dictionaries, functions, file handling, and modules. Each section includes simple code examples demonstrating the respective concepts. The content is aimed at beginners learning programming basics.

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

Basic Input Output

# Program to take name and age and display a message name = input("Enter your name: ") age =
int(input("Enter your age: ")) print("Hello", name) print("You will be", age + 1, "years old next year")
Data Types
# Demonstrating different data types a = 10 b = 3.5 c = "Python" d = True print(type(a), type(b),
type(c), type(d))
Operators
# Arithmetic operators a = 10 b = 3 print(a + b, a - b, a * b, a / b, a % b)
Conditional Statements
# Check whether a number is even or odd num = int(input("Enter a number: ")) if num % 2 == 0:
print("Even") else: print("Odd")
Loops
# Print first 10 natural numbers using loop for i in range(1, 11): print(i)
Strings
# String operations s = "Computer Science" print([Link]()) print([Link]()) print(len(s))
Lists
# List operations numbers = [1, 2, 3, 4, 5] [Link](6) [Link](3) print(numbers)
Tuples
# Tuple example t = (10, 20, 30) print(t[1]) print(len(t))
Dictionary
# Dictionary example student = {"name": "Aman", "class": 11, "marks": 85} print(student["name"])
print([Link]())
Functions
# Function to calculate square of a number def square(n): return n * n print(square(5))
File Handling
# Write and read from a file f = open("[Link]", "w") [Link]("Hello File") [Link]() f = open("[Link]",
"r") print([Link]()) [Link]()
Modules
# Using math module import math print([Link](16)) print([Link](5))

You might also like