Python Questions: N 5 For I in Range (0, N) : For J in Range (0, N) : Print (" ",end " ") Print ("/T")
Python Questions: N 5 For I in Range (0, N) : For J in Range (0, N) : Print (" ",end " ") Print ("/T")
1)
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
n=5
for i in range(0,n):
for j in range(0,n):
print("*",end=" ")
print("\t")
2)
*****
* *
* *
* *
*****
n=5
for i in range(n):
for j in range(n):
print("*",end="")
else:
print(" ",end="")
print("\t")
3)
*
**
***
****
*****
for i in range(0,n+1):
for j in range(0,i):
print('*',end=" ")
print("\t")
4)
*
**
***
****
*****
size=5
for i in range(size):
for j in range(1,size-i):
print(' ',end="")
for k in range(0,i+1):
print('*',end="")
print()
5)
**
**
* *
* *
******
size=5
for i in range(size):
for j in range(size):
print("*",end="")
else:
print(" ",end="")
print("\t")
6)
*****
****
***
**
*
for i in range(0,5):
for j in range(i,5):
print("*",end=' ')
print("\t")
7)
*
***
*****
*******
*********
... whereas an iterator yields a number of objects in a specific order, often creating them on
the fly as requested:
my_iter = iter(range(1000000000000))
my_iter
next(my_iter)
A Singleton pattern in python is a design pattern that allows you to create just
one instance of a class, throughout the lifetime of a program. Using a singleton
pattern has many benefits. A few of them are:
To limit concurrent access to a shared resource.
To create a global point of access for a resource.
To create just one instance of a class, throughout the lifetime of a
program.
10. How to open a database connection? How the application understands from
where the query is to be read?
Q. Common Elements
Given two 1-dimensional arrays containing strings of lowercase alphabets, print the elements
that are common in both the arrays i.e. the strings that are present in both the ar
com=[]
for i in range(0,len(Array_2)):
for j in range(0,len(Array_1)):
if Array_2[i]==Array_1[j]:
com.append(Array_2[i])
Array_1[j]=""
print(Array_1)
break
print(com)
print(Array_1)
print(Array_2)
Largest Sum Contiguous Subarray
Difficulty Level : Medium
Last Updated : 01 Dec, 2021
Write an efficient program to find the sum of contiguous subarray within a one-
dimensional array of numbers that has the largest sum.
max=-99999
l=[]
for i in range(0,len(a)):
for j in range(0,len(a)):
sum_max=sum(a[i:(len(a)-j)])
if max<sum_max:
max=sum_max
print(max)
Q3. Write a program: single input as a string(lets say "aaabcccfffghh"), you have to return the
char and their occurrence as a string. In this case you have to return "a3b1c3f3g1h2"
a="aaabcccfffghh"
li=[]
for i in a:
li.append(i+str(a.count(i)))
print(''.join(li))
__init__ method
"__init__" is a reseved method in python classes. It is called as a constructor in object
oriented terminology. This method is called when an object is created from a class and
it allows the class to initialize the attributes of the class.
Question:
Find number of i’s in a dataframe column
df['empname'].str.findall('i').sum()