33 0 50KB
For Loop
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