0% found this document useful (0 votes)
111 views

Lecture-3 Pagle

The document discusses different programming concepts in Python including libraries, flow control, looping, nested loops, jump statements, and the difference between == and is operators. It also includes examples of importing libraries, conditional statements, storing and checking conditions, for, while, and nested loops, break and continue statements, and practice problems evaluating expressions and finding errors in code snippets.

Uploaded by

Rudra Pratap
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
111 views

Lecture-3 Pagle

The document discusses different programming concepts in Python including libraries, flow control, looping, nested loops, jump statements, and the difference between == and is operators. It also includes examples of importing libraries, conditional statements, storing and checking conditions, for, while, and nested loops, break and continue statements, and practice problems evaluating expressions and finding errors in code snippets.

Uploaded by

Rudra Pratap
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Libraries

We don’t need everything in our program, that’s why different Libraries are made.

For e.g.
import math now i have some powers of math library

pow(base,exp) sqrt(num) sin(num)


Flow of Control
A = int( input( ) )
1. Conditional Statements if(A==1):
a. If print(“One.”)
b. If else if(A==2):
c. If elif else print(“Two”.)
if(A==3):
print(“Three”)
else:
print(“upar vaale se daro...”)
A = int(input( ))
B = int(input( )) Storing Condition
C = int(input( ))

D= A>B and B>C


if D:
print(“Ascending”)
else :
print(“Not Ascending.”)
Looping Statements
Used to repeat a block in the program.

1. For loop
for <variable> in <sequence> :
2. While loop
/statements/

while <condition> :
/statements/
Egg jaampal

num = int( input(‘Enter the number : ’) )


for i in range(1,11):
print(num*i)

while i<11:
print(num*i)
Loop else statements
for <variable> in <sequence>: while <condition>:
statements statements
else : else :
statements statements

When for runs fully Until condition becomes false


Jump Statements
Python offers two jump statements break and continue.

Using these we can jump out of a running loop.

for i in range(20,1,-1): for i in range(20,1,-1):


print(i) print(i)
if(i==11): if(i==11):
break continue
Nested Loops
There can be a loop in a loop.
There can also be a loop in a loop in a loop in a loop in a loop…… and so on.

for i in range(1,6):
for j in range(1,6):
print(i*j,end=”___”)
print(“\n”)
Difference in == and is
a = ‘Harsh’
b= input(“Enter the name : “)
if(a==b): Cases :
print(“true”)
else 1. Strings are inputted.
print(“false”) 2. Very large integers.
3. Floating points & Complex Literals
if(a is b):
print(“true”)
else:
print(“false”)
Practice Time
1. Evaluate : 14 + 13 % 15
2. Write the command to print : E:\New Folder\list.txt
3. Which will give an error:
a. float(‘12’)
b. int(‘12’)
c. float(‘12.5’)
d. int(‘12.5’)
4. In a nested loop break statement breaks all the loops in one go?
Practice Time
1. Find the output : 2. Mark the mistakes :

name = ‘Mr.Harsh07’ 30=to


print(‘WELCOME’) For K in range(0,to):
print(‘Hello’, name) if k%4 == 0 :
print(‘What’s up?) print(K*4)
else :
print(K+3)
Practice Time
1. Write a program that takes time in seconds and shows it in
minutes and seconds.
3. Is the loop infinite? Give reasons.
2. x=10
y=0
m=3
while x>y :
n=5
print(x,y)
while n<10:
x=x-1
m=n-1
y=y+1
n=2*n-m
print(n,m)
Practice Time
1. Find errors: 2. Find the error and print the output:
x=True For i in range(1,15,):
y=False if i%3=0 and i%5=0:
z=false print ‘a’
If x,y,z : continue
print ‘yes’ else if i%3=0:
else: continue
print ‘no’ else i%%5=0:
print(‘lol’)
print(‘Trolol’)

You might also like