Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please help- me format the code below to Press any key to start Task n, where n is the task number (1, 2, or 3)

please help- me format the code below to Press any key to start Task n, where n is the task number (1, 2, or 3) . I put the number in front but for it to work in python you have to remove it

1)def hasUpper(password): for x in password: if x.islower(): return True  return False  def hasLower(password): for x in password: if x.islower(): return True  return False  def hasDigits(password): count = 2 for x in password: if x.isnumeric(): count+=1 return count>=2 def checkLength(password): return len(password)>=8 def specialCharCheck(password): for x in password: if(x in "$#@"): return True  return False  def main(): password = input("Enter your password: ") if(hasUpper(password) and hasLower(password) and hasDigits(password) and checkLength(password) and specialCharCheck(password)): print('Password accepted!') else: print("Password not matched.") main() 

2)def check_every_integer(*mat): flag=0 check=[int(0) for x in range(0,17)] for i in range(0,4): for j in range(0,4): check[int(mat[i][j])]=check[int(mat[i][j])]+1

i=1; while i<=16: if check[i]!=1: flag=1 break i=i+1 if flag==1: print("Not every integer used exactly once") return flag

# for printing the matix read from the file def print_matrix(*mat): for i in range(0,4): for j in range(0,4): print(repr(mat[i][j]).rjust(2),end=' ') print("")

#for checking the bad diagonal sum def bad_diagonal_sum(*mat): sum = 34 flag=0 diaognal_2_sum=0 diaognal_1_sum=0 for i in range(0,4): for j in range(0,4): if(i==j): diaognal_1_sum=diaognal_1_sum+int(mat[i][j]) diaognal_2_sum=diaognal_2_sum+int(mat[i][3-j]) if(diaognal_1_sum!=sum): flag=1 print("Bad diagonal sum = ",format(diaognal_1_sum)) if (diaognal_2_sum!=sum): flag=1 print("Bad diagonal sum = ",format(diaognal_2_sum)) return flag

# for checking bad row sum def bad_row_sum(*mat): sum = 34 flag=0 for i in range(0,4): cur_row_sum=0 for j in range(0,4): cur_row_sum=cur_row_sum+int(mat[i][j]) if sum!=cur_row_sum: flag=1 print("Bad row sum = ",format(cur_row_sum)) return flag

#for checking bad column sum def bad_col_sum(*mat): sum = 34 flag=0 for i in range(0,4): cur_col_sum=0 for j in range(0,4): cur_col_sum=cur_col_sum+int(mat[j][i]) if sum!=cur_col_sum: flag=1 print("Bad column sum = ",format(cur_col_sum)) return flag

# return 0 if matix is magic otherwise 1 def isMagic(*mat): ans=bad_row_sum(*mat) ans=ans+bad_col_sum(*mat) ans=ans+bad_diagonal_sum(*mat) ans=ans+check_every_integer(*mat) return ans

file_name = input("Which file?")

while True: if file_name.startswith("q") or file_name.startswith("Q"): break; fh = open(file_name) mat=[] for line in fh: line = line.split(" ") line = [int(x) for x in line] for x in line: mat.append(x) fh.close() # convert list mat into matrix of 4*4 matrix = [mat[i:i+4] for i in range(0, 16, 4)] # print(matrix) print_matrix(*matrix) #check is matrix is magic or not ans=isMagic(*matrix) if ans==0: print("It is a magic matrix")

file_name = input("Which file?")

print("DONE")

3)def getNumber(alphabet): if alphabet in "ABC": return "2" elif alphabet in "DEF": return "3" elif alphabet in "GHI": return "4" elif alphabet in "JKL": return "5" elif alphabet in "MNO": return "6" elif alphabet in "PQRS": return "7" elif alphabet in "TUV": return "8" elif alphabet in "WXYZ": return "9" else: return alphabet def main(): number = input('Enter a number in string format: ') s = '' number = number.upper() for ch in number: s += getNumber(ch) print('%s in number format is %s' % (number, s)) if __name__ == '__main__': main() 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions

Question

Explain the functions of financial management.

Answered: 1 week ago

Question

HOW MANY TOTAL WORLD WAR?

Answered: 1 week ago

Question

Discuss the scope of financial management.

Answered: 1 week ago

Question

Discuss the goals of financial management.

Answered: 1 week ago