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

? Chapter 6 Python Fundamentals

Uploaded by

ffstellartsr0219
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)
197 views12 pages

? Chapter 6 Python Fundamentals

Uploaded by

ffstellartsr0219
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/ 12

Chapter: Python Fundamentals

Subject: Class 11 Computer Science


Book: Sumita Arora (CBSE)

DETAILED NOTES

1. What is Python?

• A high-level, interpreted, general-purpose programming language.

• Created by Guido van Rossum in 1991.

• Python supports object-oriented, procedural, and functional programming paradigms.

2. Python Character Set

The character set used in Python includes:

• Letters (A-Z, a-z)

• Digits (0-9)

• Special symbols: + - * / = @ # % ^ & ! ~ etc.

• White spaces (space, tab, newline)

• Other Unicode characters

3. Tokens in Python

Tokens are the smallest individual units in a program.

Token Type Examples

Keywords if, else, while, for, def, etc.

Identifiers Variable names like x, total, marks

Literals 10, 3.14, 'Hello', True

Operators +, -, *, /, ==, etc.

Punctuators :, ,, (), {}, []

4. Literals in Python

Literals are constant values assigned to variables.


Type Example

Numeric 100, 3.14

String 'Hello', "Python"

Boolean True, False

None None

5. Identifiers

• Names given to variables, functions, classes, etc.

• Rules:

o Must begin with a letter or underscore

o Cannot be a keyword

o Can include digits but not as the first character

Valid: name, _total, marks123


Invalid: 123name, for, total@

6. Keywords

Reserved words with special meaning in Python.


Examples: if, else, elif, for, while, break, continue, def, return, True, False, None

7. Operators

Used to perform operations on variables and values.

Operator Type Examples

Arithmetic +, -, *, /, //, %, **

Relational <, >, <=, >=, ==, !=

Logical and, or, not

Assignment =, +=, -=, *=, /=

8. Input and Output Functions

• input() – Takes user input (always as a string)

• print() – Displays output on the screen


name = input("Enter your name: ")

print("Hello", name)

9. Data Types in Python

Type Example

int 10, -5

float 3.14, 0.5

str "Hello"

bool True, False

NoneType None

10. Errors in Python

Type Example

Syntax Error print("Hello' – unmatched quote

Runtime Error 10 / 0 – division by zero

Logical Error Incorrect output despite no errors

IMPORTANT QUESTIONS

1-Mark Questions

1. Who developed Python?

2. What is a keyword? Give two examples.

3. Define literals with examples.

4. Name any four data types in Python.

5. What will be the output of: print(3 + 2.5)?

2-Mark Questions

1. Differentiate between a compiler and an interpreter.

2. Write rules for naming Python identifiers.


3. What is the difference between = and == in Python?

4. What are tokens? List their types.

5. What are the different types of literals in Python?

3/5-Mark Questions

1. Explain Python character set and its components.

2. Write a program to accept two numbers and display their sum, difference, product, and
quotient.

3. What are operators? Explain any four types of operators in Python.

4. Explain the different data types used in Python with examples.

5. What is the role of input() and print() functions? Write suitable examples.

Output/Code-based Questions

1. Predict the output:

2. a = 10

3. b = 3

4. print(a / b)

5. print(a // b)

6. print(a ** b)

7. Find and correct the errors:

8. for = 5

9. print("value is" + for)

10. Write a program to:

o Accept user’s name and age

o Print a message: “Hello [name], you are [age] years old.”

SOLUTIONS – PYTHON FUNDAMENTALS (Class 11)

1-Mark Questions
1. Who developed Python?
→ Guido van Rossum

2. What is a keyword? Give two examples.


→ Keywords are reserved words in Python that have special meaning and cannot be used as variable
names.
Examples: if, return

3. Define literals with examples.


→ Literals are fixed values that appear directly in the code.
Examples: 10 (int), "Python" (string), 3.14 (float)

4. Name any four data types in Python.


→ int, float, str, bool

5. What will be the output of: print(3 + 2.5)?


→ 5.5 (Integer + Float results in a Float)

2-Mark Questions

1. Differentiate between a compiler and an interpreter.

Compiler Interpreter

Translates the whole code at once Translates one line at a time

Faster execution Slower than compiled code

Used in C, C++ Used in Python

2. Write rules for naming Python identifiers.

• Must start with a letter (A–Z or a–z) or underscore _

• Cannot start with a digit

• Can include digits (0–9) and underscores

• Cannot be a keyword

• Case-sensitive

3. What is the difference between = and == in Python?

• = is the assignment operator (assigns value).

• == is the comparison operator (checks equality).


Example:
x=5 # assignment

print(x == 5) # comparison → True

4. What are tokens? List their types.


→ Tokens are the smallest elements in Python.
Types: Keywords, Identifiers, Literals, Operators, Punctuators

5. What are the different types of literals in Python?

• Numeric Literal: 100, 3.14

• String Literal: "Hello"

• Boolean Literal: True, False

• Special Literal: None

3/5-Mark Questions

1. Explain Python character set and its components.


Python uses the following character set:

• Letters: A–Z, a–z

• Digits: 0–9

• Special Symbols: + - * / = ! % ^ & @ etc.

• White spaces: Space, tab, newline

• Unicode characters (for international languages)

2. Write a program to accept two numbers and display their sum, difference, product, and
quotient.

a = float(input("Enter first number: "))

b = float(input("Enter second number: "))

print("Sum:", a + b)

print("Difference:", a - b)

print("Product:", a * b)

print("Quotient:", a / b)
3. What are operators? Explain any four types of operators in Python.

→ Operators perform operations on variables and values.

Type Examples Description

Arithmetic + - * / // % ** Basic mathematical operations

Relational > < >= <= == != Compare two values

Logical and or not Combine boolean expressions

Assignment = += -= *= Assign values to variables

4. Explain the different data types used in Python with examples.

Data Type Example Description

int x = 10 Whole numbers

float y = 3.14 Decimal numbers

str name = "Ali" Text/String

bool flag = True Boolean (True/False)

NoneType z = None Represents null or no value

5. What is the role of input() and print() functions? Write suitable examples.

• input() is used to take user input (always returns a string).

• print() is used to display output.

Example:

name = input("Enter your name: ")

print("Hello", name)

Output/Code-based Questions

1. Predict the output:

a = 10

b=3
print(a / b) # 3.333...

print(a // b) # 3 (floor division)

print(a ** b) # 1000

Output:

3.3333333333333335

1000

2. Find and correct the errors:

for = 5 # 'for' is a keyword

print("value is" + for) # Type error: can't add string and int

Corrected Code:

value = 5

print("Value is " + str(value))

3. Write a program to:

• Accept user’s name and age

• Print: “Hello [name], you are [age] years old.”

name = input("Enter your name: ")

age = input("Enter your age: ")

print("Hello", name + ", you are " + age + " years old.")

Here’s a curated set of additional practice questions with solutions for the “Python Fundamentals”
chapter (Class 11 Computer Science, Sumita Arora, CBSE) to help you deepen your understanding:

MORE PRACTICE QUESTIONS WITH SOLUTIONS

Chapter: Python Fundamentals


Class 11 – Computer Science (CBSE)

A. Conceptual Questions
Q1. Differentiate between mutable and immutable data types in Python.
Answer:

• Mutable: Can be changed after creation (e.g., list, dict)

• Immutable: Cannot be changed after creation (e.g., int, float, str, tuple)

Q2. List any 5 Python keywords and explain their use.


Answer:

Keyword Use

if Conditional statement

def Used to define a function

return Returns value from a function

True Boolean true value

None Represents no value

Q3. What will be the data type of the following expressions?

type(7) → int

type(3.5) → float

type("hello") → str

type(True) → bool

type(None) → NoneType

B. Code Output Questions

Q4. Predict the output:

x=4

y=5

x += y

print(x)

print(y)

Answer:

9
5

Q5. What will be the output of the following code?

a = "10"

b=5

print(a * b)

Answer:

1010101010

Because "10" * 5 means string "10" repeated 5 times.

Q6. What will be the result of this?

a = 10

b=3

print(a % b)

print(a ** b)

Answer:

1000

C. Error Finding Questions

Q7. Find the error in the following code and correct it:

Print("Hello World!)

Error: Print should be print, and string is not closed.


Correct Code:

print("Hello World!")

Q8. Identify the error:

num1 = input("Enter number: ")

num2 = input("Enter number: ")

print("Sum is:", num1 + num2)


Problem: input() returns strings → so concatenation happens.
Fix:

num1 = int(input("Enter number: "))

num2 = int(input("Enter number: "))

print("Sum is:", num1 + num2)

D. Coding Practice Questions

Q9. Write a program to calculate the square and cube of a number entered by the user.

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

print("Square:", num ** 2)

print("Cube:", num ** 3)

Q10. Write a Python program to find the average of three numbers.

a = float(input("Enter first number: "))

b = float(input("Enter second number: "))

c = float(input("Enter third number: "))

average = (a + b + c) / 3

print("Average:", average)

Q11. Write a program to swap two numbers without using a third variable.

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

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

a, b = b, a

print("After swapping:")

print("a =", a)

print("b =", b)
Q12. Write a program that takes a user’s name and prints a welcome message.

name = input("Enter your name: ")

print("Welcome", name + "!")

Q13. Write a program to calculate the simple interest.

p = float(input("Enter principal: "))

r = float(input("Enter rate of interest: "))

t = float(input("Enter time (in years): "))

si = (p * r * t) / 100

print("Simple Interest:", si)

Q14. Write a program to convert temperature from Celsius to Fahrenheit.

celsius = float(input("Enter temperature in Celsius: "))

fahrenheit = (celsius * 9/5) + 32

print("Temperature in Fahrenheit:", fahrenheit)

You might also like