-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNested_loop_&_Pattern.py
More file actions
executable file
·94 lines (77 loc) · 2.37 KB
/
Nested_loop_&_Pattern.py
File metadata and controls
executable file
·94 lines (77 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#---------------------------- Pattern Printing -----------------------------------------#
#---------------------------------------------------------------------------------------#
#1.
for f in range(4): # Here f is printing the number of the rows and his columns
for h in range(4): #0 to 3
print("# ", end="")
print() # print new line
print('-----------------')
#-----------------------------------------------------------------------------#
#2.
for i in range(4):
for h in range(4-i):
print("# ", end="")
#h+=1
print()
#---------------------------------------------------------------------------------------#
# Pattern : # 1 2 3 4 2. A P Q R
# 2 3 4 A B Q R
# 3 4 A B C R
# 4 A B C D
#--------------------------------------------------------------------------------#
# Prime Number or Not: a number if divisible by 1 or itself is prime number
p_num = 15
for i in range(2,p_num):
if p_num%i== 0:
print("Not a prime number ")
break
else:
print("prime Number")
# Make it efficient
#-------------------------------------------------------------------------------------#
#nested For Loop
#1. Outer loop
#2.Inner Loop
list1 =[1,2,3,4,5,6,7,8,9]
list2 =[1,2,3,4,5,6,7,8,9]
count=0
#outer_loop
for x in list1:
count+=1
#inner loop
for y in list2:
count+=1
print(count)
#outer loop
for i in range(10):
#innner loop
for j in range(10):
print(0,end =" ")
print() #separating the line
import time
start_time=time.time()
# #outer loop
# for i in range(10):
# #inner loop
# for j in range(100):
# print(0, end=" ")
# print()
# print(round((time.time()-start_time),2))
# # so we have to optimizee our code to run efficiently and effectively
# #Enumearte function
# # finding the number in a list with the help of the enumerate function
# num_list = [33,42,5,66,77,22,16,79,36,62,78,43,88,39,53,67,89,11]
# for x,num in enumerate(num_list):
# if num == 36:
# print('Number found at ', x)
#--------------------------------------------------------------------------------#
# *
# * *
# * * *
# * * * *
for i in range(1,5):
for j in range(5-i):
print(" ",end="")
for k in range(i):
print("* ", end="")
print()