Professional Documents
Culture Documents
print("List Iteration")
li = ["prashant", "ashish", "sandip"]
for i in li:
print(i)
print("\nTuple Iteration")
t = ("prashant", "ashish", "sandip")
for i in t:
print(i)
# Iterating over a String
print("\nString Iteration")
s = "prashant"
for i in s :
print(i)
r=range(10)
for i in r :
print(i)
r = range(10,20)
for i in r :
print(i)
#2 means increment value
r = range(20,30,2)
for i in r :
print(i)
'''l = list(range(10))
print(l) '''
#=======================================================================
''' 1 2 3 4 (col=j)
1 1
2 2 2
3 3 3 3
4
(row=i)
i =2
j= 1 '''
for i in range(1, 5): # outer loop = row
for j in range(i): # inner loop = col
print(i, end=' ')
print()
name = ["prashant", "Ashish", "Rajesh"]
for x in name:
print(x)
if x == "Ashish":
break
name = [3,5,7,1,11,4,5,2]
for x in name:
if x == 2 or x==4 or x== 6 or x==8 or x==10:
print("which even no is found",x)
a,b,c= [int(x) for x in input("Enter 2 numbers :").split()]
print("Product is :", a*b, c)
#Note: split() function can take space as seperator by default .But we can pass
anything as seperator.
While loop
a = 200
b = 3000
if b > a:
print("b is greater than a")
elif a == b:
print("a and b are equal")
else:
print("a is greater than b")
'''Logical (and)
T T T
logical (or)
F F F '''
a = 200
b = 33
c = 500
if a > b and c > a:
print("Both conditions are True")
p1=int(input("Enter paper1 marks"))
p2=int(input("Enter paper2 marks"))
p3=int(input("Enter paper3 marks"))
p4=int(input("Enter paper4 marks"))
p5=int(input("Enter paper5 marks"))
if p1 >=40 and p2>=40 and p3>=40 and p4>=40 and p5>=40:
print("you are pass")
else:
print("you are fail")
a = 200
b = 33
c = 500
if a > b or a > c:
print("At least one of the conditions is True")
ch=str(input("Enter any charecter"))
if ch=='a' or ch=='e' or ch=='i' or ch=='o' or ch=='u': and ch=='A' or
print("this is vowel")
else:
print("this is consonent")
a = 33
b = 200
if b > a:
pass
print("nothinf for pass")
for charecter in 'prashantjha':
if charecter == 'a' or charecter == 'j':
break
print('Current Letter :', charecter)
Escape:
name = "prashant \n jha"
print(name)
name = "prashant \t jha"
print(name)
name = "prashant \" jha"
print(name)
While loop
i = 1
while i < 6:
print(i)
i += 2
i = 1
while i < 6:
print(i)
if i == 3:
break
i += 1
i = 0
while i < 6:
i += 1
if i == 3:
continue
print(i)
'''name=input("Enter Name:")
if name=="Ashish" :
print("Hello my name is ashish but i am not a tester")'''
'''brand=input("Enter Your coldrink name:")
if brand=="pepsi" :
print(" take in morining")
elif brand=="Dew":
print("dar ke age jeet hai")
elif brand=="Thumbsup":
print(" tase the thunder")
else :
print("go for other brand")'''
'''n1=int(input("Enter First Number:"))
n2=int(input("Enter Second Number:"))
n3=int(input("Enter Third Number:"))
if n1>n2 and n1>n3:
print("Biggest Number is:",n1)
elif n2>n3:
print("Biggest Number is:",n2)
else :
print("Biggest Number is:",n3)'''
#Q. Write a program to check whether the given number is in between 1 and 100?
'''name=input("Enter name: ")
i=0
for x in name :
print("The character present at ",i,"index no is :",x)
i=i+1 # update by one '''
#To display numbers from 10 to 1 in descending order
'''for x in range(10,0,-1) : #(initailization(start point) , Termination(stop po
int), updation(inc/dec))
print(x) '''
#To print sum of numbers presenst inside list
'''list=eval(input("Enter List item:"))
sum=0
for x in list:
sum=sum+x
print("The Sum=",sum)'''
# To display the sum of first n numbers
'''n=int(input("Enter number:"))
sum=0
i=1
while i<=n:
sum=sum+i
i=i+1
print("The sum of first",n,"numbers is :",sum)'''
# a user to enter name until entering Amrut
'''name=""
while name!="Amrut":
name=input("Enter your Name:")
print("Thanks for entering valid name")'''
'''n = int(input("Enter number of rows:"))
for i in range(1,n+1):
for j in range(1,i+1):
print("*",end=" ")
print() '''
'''for i in range(20):
if i==12:
print("this is right time to take break")
break
print(i)'''
'''mycart=[10,20,800,60,700]
for item in mycart:
if item>400:
print("This my own cart item")
break
print(item)'''
#To print odd numbers in the range 0 to 9
#
'''for i in range(9):
if i%2==0:
continue
print(i) '''
'''mycart=[10,20,800,60,700]
for item in mycart:
if item>400:
print("This is not in my budget")
continue
print(item) '''
#using else block
'''mycart=[10,20,68,60,70]
for item in mycart:
if item>400:
print("This is not in my budget")
continue
print(item)
else:
print("you have purchased everything")'''