Python Chapter 2

Chapter 2 Python Programs

Yahan aap dekhoge ke code likhne par screen par kya aata hai. Phir aap khud answer doge aur har sawal ko step by step samjhoge.

Jo likho, woh screen par kaise aata hai?

Naam aur marks badlo, phir dekho Python unhen screen par kaise dikhata hai.

Yaad rakho

Pehle cheez variable me jati hai. Phir `print()` us cheez ko screen par dikhata hai.

Python kya likhega

name = "Ali"
marks = 87
print("Name:", name)
print("Marks:", marks)

Screen par kya dikhega

Name: Ali

Marks: 87

Program Practice

Yeh wale sawal try karo

Jo sawal karna ho us par click karo. Neeche usi page par poora hal mil jayega.

Full Practice

Ab sab sawal yahin karo

Sawal 8

1 of 8

Question 8

Is code ka output predict karo:

codeeasyvariables

Pehle khud karo

Sab se pehle apna answer do. Phir hum sahi jawab dikhayenge.

name = 'Ali'
print(name)

Asaan samjhayi

Yahan simple alfaaz me bataya gaya hai ke jawab aisa kyun hai.

Variable name ke andar 'Ali' store hai, print(name) wahi value dikhaye ga.

Poora hal

Pehle try karo, phir yeh aur achi tarah samajh aayega.

  1. Step 1

    name variable ke andar 'Ali' store kiya gaya hai.

  2. Step 2

    print(name) variable ki stored value show karta hai.

  3. Step 3

    Final output: Ali.

Code

name = 'Ali'
print(name)

Chalo step by step karte hain

Har step alag dikhaya gaya hai taake kuch bhi miss na ho.

  1. Step 1

    name variable ke andar 'Ali' store kiya gaya hai.

  2. Step 2

    print(name) variable ki stored value show karta hai.

  3. Step 3

    Final output: Ali.

Akhri jawab

Ali

Aur samjho

Agar yeh mushkil lag raha hai to yeh topics kholo:

Sawal 9

2 of 8

Question 9

Is code ka output kya hai?

codemediumoperators

Pehle khud karo

Sab se pehle apna answer do. Phir hum sahi jawab dikhayenge.

age = 18
print(age > 16)

Asaan samjhayi

Yahan simple alfaaz me bataya gaya hai ke jawab aisa kyun hai.

18, 16 se bara hai is liye comparison ka result True ho ga.

Poora hal

Pehle try karo, phir yeh aur achi tarah samajh aayega.

  1. Step 1

    age variable ki value 18 hai.

  2. Step 2

    Expression 18 > 16 evaluate hoti hai.

  3. Step 3

    Yeh condition true hai, is liye output True aata hai.

Code

age = 18
print(age > 16)

Chalo step by step karte hain

Har step alag dikhaya gaya hai taake kuch bhi miss na ho.

  1. Step 1

    age variable ki value 18 hai.

  2. Step 2

    Expression 18 > 16 evaluate hoti hai.

  3. Step 3

    Yeh condition true hai, is liye output True aata hai.

Akhri jawab

True

Aur samjho

Agar yeh mushkil lag raha hai to yeh topics kholo:

Sawal 12

3 of 8

Question 12

Output predict karo:

codehardoperators

Pehle khud karo

Sab se pehle apna answer do. Phir hum sahi jawab dikhayenge.

a = 10
b = 3
print(a // b)

Asaan samjhayi

Yahan simple alfaaz me bataya gaya hai ke jawab aisa kyun hai.

Floor division decimal ko drop karke integer quotient deti hai.

Poora hal

Pehle try karo, phir yeh aur achi tarah samajh aayega.

  1. Step 1

    a // b floor division hai.

  2. Step 2

    10 / 3 ka quotient 3.33 hota hai.

  3. Step 3

    Floor division decimal part drop kar deti hai, is liye output 3 hai.

Code

a = 10
b = 3
print(a // b)

Chalo step by step karte hain

Har step alag dikhaya gaya hai taake kuch bhi miss na ho.

  1. Step 1

    a // b floor division hai.

  2. Step 2

    10 / 3 ka quotient 3.33 hota hai.

  3. Step 3

    Floor division decimal part drop kar deti hai, is liye output 3 hai.

Akhri jawab

3

Aur samjho

Agar yeh mushkil lag raha hai to yeh topics kholo:

Sawal 15

4 of 8

Question 15

Evaluate the expression: 10 + 3 * 2 and explain the order of evaluation.

longmediumoperators

Pehle khud karo

Sab se pehle apna answer do. Phir hum sahi jawab dikhayenge.

Apna jawab likho. Button dabane ke baad hum sahi jawab aur asaan steps dikhayenge.

Asaan samjhayi

Yahan simple alfaaz me bataya gaya hai ke jawab aisa kyun hai.

Expression solve karte waqt operator precedence follow hoti hai. Multiplication addition se pehle hoti hai.

Poora hal

Pehle try karo, phir yeh aur achi tarah samajh aayega.

  1. Step 1

    Expression mein pehle multiplication dekho: 3 * 2.

  2. Step 2

    3 * 2 = 6.

  3. Step 3

    Ab 10 + 6 karo.

  4. Step 4

    Final result 16 aata hai.

Chalo step by step karte hain

Har step alag dikhaya gaya hai taake kuch bhi miss na ho.

  1. Step 1

    Expression mein pehle multiplication dekho: 3 * 2.

  2. Step 2

    3 * 2 = 6.

  3. Step 3

    Ab 10 + 6 karo.

  4. Step 4

    Final result 16 aata hai.

Akhri jawab

16

Aur samjho

Agar yeh mushkil lag raha hai to yeh topics kholo:

Sawal 16

5 of 8

Question 16

Write a short note on variables and how they are used in Python programs.

longmediumvariables

Pehle khud karo

Sab se pehle apna answer do. Phir hum sahi jawab dikhayenge.

Apna jawab likho. Button dabane ke baad hum sahi jawab aur asaan steps dikhayenge.

Asaan samjhayi

Yahan simple alfaaz me bataya gaya hai ke jawab aisa kyun hai.

Long answer mein definition, purpose, aur simple example teenon cover hone chahiye.

Poora hal

Pehle try karo, phir yeh aur achi tarah samajh aayega.

  1. Step 1

    Variable aik naam hota hai jo value ko temporarily store karta hai.

  2. Step 2

    Python mein variable ke through number, text, ya boolean value store ki ja sakti hai.

  3. Step 3

    Program later isi naam ko use karke value read ya print karta hai.

  4. Step 4

    Example: marks = 87, phir print(marks).

Chalo step by step karte hain

Har step alag dikhaya gaya hai taake kuch bhi miss na ho.

  1. Step 1

    Variable aik naam hota hai jo value ko temporarily store karta hai.

  2. Step 2

    Python mein variable ke through number, text, ya boolean value store ki ja sakti hai.

  3. Step 3

    Program later isi naam ko use karke value read ya print karta hai.

  4. Step 4

    Example: marks = 87, phir print(marks).

Akhri jawab

Variables are named storage locations used to keep data such as numbers or text so the program can reuse them later.

Aur samjho

Agar yeh mushkil lag raha hai to yeh topics kholo:

Sawal 23

6 of 8

Question 23

Evaluate the following expressions: (a) 18 / 3 + 4 * 2 (b) (25 + 5 * 2) - 8 / 2 (c) 12 + (6 * 5) ** 2 / (40 + 2 - 7) + 10 (d) 45 / (2 * 2 + 3) + 4 * 6 - 7

longhardoperators

Pehle khud karo

Sab se pehle apna answer do. Phir hum sahi jawab dikhayenge.

Apna jawab likho. Button dabane ke baad hum sahi jawab aur asaan steps dikhayenge.

Asaan samjhayi

Yahan simple alfaaz me bataya gaya hai ke jawab aisa kyun hai.

Operator precedence follow karna zaroori hai warna result galat hoga.

Poora hal

Pehle try karo, phir yeh aur achi tarah samajh aayega.

  1. Step 1

    BODMAS ya operator precedence follow karo.

  2. Step 2

    Brackets pehle solve karo.

  3. Step 3

    Phir powers, phir multiplication/division, phir addition/subtraction.

  4. Step 4

    Har expression ko isi order mein simplify karo.

Chalo step by step karte hain

Har step alag dikhaya gaya hai taake kuch bhi miss na ho.

  1. Step 1

    BODMAS ya operator precedence follow karo.

  2. Step 2

    Brackets pehle solve karo.

  3. Step 3

    Phir powers, phir multiplication/division, phir addition/subtraction.

  4. Step 4

    Har expression ko isi order mein simplify karo.

Akhri jawab

Expressions ko precedence order se solve kiya jata hai: brackets, powers, multiplication/division, then addition/subtraction.

Aur samjho

Agar yeh mushkil lag raha hai to yeh topics kholo:

Sawal 24

7 of 8

Question 24

Write a Python program to check whether a number is positive, negative or zero.

longmediumoperators

Pehle khud karo

Sab se pehle apna answer do. Phir hum sahi jawab dikhayenge.

Apna jawab likho. Button dabane ke baad hum sahi jawab aur asaan steps dikhayenge.

Asaan samjhayi

Yahan simple alfaaz me bataya gaya hai ke jawab aisa kyun hai.

Conditional statements use hotay hain decision making ke liye.

Poora hal

Pehle try karo, phir yeh aur achi tarah samajh aayega.

  1. Step 1

    User se number input lo.

  2. Step 2

    Agar number > 0 ho to Positive print karo.

  3. Step 3

    Agar number < 0 ho to Negative print karo.

  4. Step 4

    Warna Zero print karo.

Code

num = int(input('Enter number: '))
if num > 0:
    print('Positive')
elif num < 0:
    print('Negative')
else:
    print('Zero')

Chalo step by step karte hain

Har step alag dikhaya gaya hai taake kuch bhi miss na ho.

  1. Step 1

    User se number input lo.

  2. Step 2

    Agar number > 0 ho to Positive print karo.

  3. Step 3

    Agar number < 0 ho to Negative print karo.

  4. Step 4

    Warna Zero print karo.

Akhri jawab

Use if / elif / else with comparisons > 0, < 0, and else for zero.

Aur samjho

Agar yeh mushkil lag raha hai to yeh topics kholo:

Sawal 25

8 of 8

Question 25

Write a Python program using while loop that prints all odd numbers between 1 and 100.

longmediumloops

Pehle khud karo

Sab se pehle apna answer do. Phir hum sahi jawab dikhayenge.

Apna jawab likho. Button dabane ke baad hum sahi jawab aur asaan steps dikhayenge.

Asaan samjhayi

Yahan simple alfaaz me bataya gaya hai ke jawab aisa kyun hai.

Modulo operator se odd/even check hota hai.

Poora hal

Pehle try karo, phir yeh aur achi tarah samajh aayega.

  1. Step 1

    Variable i ko 1 se start karo.

  2. Step 2

    while loop ko 100 tak chalao.

  3. Step 3

    Modulo se odd numbers check karo.

  4. Step 4

    Har odd value print karo aur i ko increment karo.

Code

i = 1
while i <= 100:
    if i % 2 != 0:
        print(i)
    i += 1

Chalo step by step karte hain

Har step alag dikhaya gaya hai taake kuch bhi miss na ho.

  1. Step 1

    Variable i ko 1 se start karo.

  2. Step 2

    while loop ko 100 tak chalao.

  3. Step 3

    Modulo se odd numbers check karo.

  4. Step 4

    Har odd value print karo aur i ko increment karo.

Akhri jawab

Use while loop with i % 2 != 0 to print odd numbers from 1 to 99.

Aur samjho

Agar yeh mushkil lag raha hai to yeh topics kholo:

More Topics

More Python Topics