How to explain this code?
elif(choice=="3"):#Search for a user
name =input("Enter the name of account: ")
surname =input("Enter the surname of the account: ")
accountExist=False
for acc in accounts:
if acc.getName()==name and acc.getSuname()==surname:
acc.displayAccountInformation()
print("")
accountExist=True
if accountExist==False:
print("\nThe account does not exist.\n")
How to explain this code???
if(choice=="1"):#Sign up: register to the system
newAccount=Account()
newAccount.signUp()
accounts.append(newAccount)
saveAccounts(accounts,FILE_NAME)
elif(choice=="2"):#Sign in
username =input("Enter the username of the account: ")
password =input("Enter the password of account: ")
accountExist=False
for acc in accounts:
def square_area(matrix,l_x,l_y,side_length):
count=2
for i in range(l_x,l_y+side_length):
for j in range(l_y,l_y+side_length):
if matrix[i][j]==1:
count+=1
else:
return 0
return count
m,n=map(int,input().split())
markers={'X':1,'O':0}
matrix=[[markers[i] for i in input().split()] for _ in range(m)]
areas=[]
for l_x in range(m):
for l_y in range(n):
for side_length in range(1,min(n-l_y+1,m-l_x+1)):
areas.append(square_area(matrix,l_x,l_y,side_length))
print(max(areas))
ouput:5
it should print output:4
for some test cases wrong?
How to explain this code?
import pathlib
import json
class Account:
#Constructor
def __init__(self):
self.username =""
self.password =""
self.name =""
self.suname =""
self.birthDate =""
self.listFriends = [] #(characterised by the account username)
#This function allows to create a new Account
def signUp(self):
self.username =input("Enter the username: ")
self.password =input("Enter the password: ")
For a given pair of words check if they are anagrams. Print
YES
if they are anagrams, or else print
NO
.
Two words are anagrams if one word can be obtained by the rearrangement of the characters in another word. Ex:
knee
and
keen
are anagrams
Note: All characters in the input will be in lower case.
you answered like this:
But this is actually calculating the area of a rectangle :
ex:
3 6
O X X X X X
O X X X X X
O X X X X X
def X_Only(Matrix:list):
for row in Matrix:
for cell in row:
# check if value is not X
if cell!='X':
return False
return True
def sub_size(lent:int):
for start in range(lent):
for stop in range(start+1, lent+1):
yield(start, stop)
def squareAreaWithX(matr:list, M:int, N:int):
maximum_area = 0
for begin_x, stop_x in sub_size(M):
for begin_y, stop_y in sub_size(N):
temp_matrix = [i[begin_y:stop_y] for i in matr[begin_x:stop_x]]
if X_Only(temp_matrix):
x= stop_x-begin_x
y= stop_y-begin_y
if maximum_area < x*y:
maximum_area=x*y
print(maximum_area)
while True:
s = input()
M, N = [int(i) for i in s.split()]
matrix=[]
for i in range(0,M):
matrix.append([N for N in input().split()])
squareAreaWithX(matrix, M, N)Given a sentence, write a program to rotate words longer than given length L by K letters towards the
right. Note: Even if K is greater than word length, rotate the word multiple times so that K letters will be rotated towards right.
Input
The first line of input will contain a string. The second line of input will contain two space separated integers, denoting L and K.
Output
The output should be a single line containing the sentence by rotating the words whose length is greater than L by K letters towards right.
Replace Elements with Zeros
Given a MXN matrix, write a program to replace all elements that do not belong to principal-diagonal & anti-diagonal with Zeros. Principal-diagonal elements are the set of elements of a matrix that lie on the line joining the top left corner to the bottom right corner. Anti-diagonal elements are the set of elements of a matrix that lie on the line joining the bottom left corner to the top right corner.
Input
The first line of input will contain two space separated integers, denoting MxN matrix. The next M lines will contain N space-separated integers.
Output
The output should be MXN matrix by replacing elements that do not belong to principal-diagonal and anti-diagonal with Zeros. Print each row as a space separated integers in a single line.
Given a sentence, write a program to mix the words based on their index locations. The first word in the output should contain the first letter of each word in the given sentence and the second word should contain the second letter of each word in the given sentence and so on.
Note: The nth word in the output should contain th letter of each word in the given sentence. The letters of the output word should be in same order as the words in the given sentence. If a word in the given sentence doesn't have n-letters, you can skip it while considering the letters of the n-th word.
Input
The input will be a single line containing a string.
The output should be a single line containing the words by mixing based on their index locations.
K Sum Unique Combinations
Given a list of integers, write a program to print the count of all possible unique combinations of numbers whose sum is equal to K.
Input
The first line of input will contain space-separated integers. The second line of input will contain an integer, denoting K.
Output
The output should be containing the count of all unique combinations of numbers whose sum is equal to K.