Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PYTHON IDLE Imagine the current password for the administrator of a server is “a

ID: 3798065 • Letter: P

Question

PYTHON IDLE

Imagine the current password for the administrator of a server is “as1987Jantu35*^ft$TTTdyuHi28Mary”.

Write a program for checking the password to login as the admin. Your program should ask the user to insert the password to access to the server. If the user inserts the correct password, print “You have successfully logged in to the server as an admin “, if not, give the user 3 other chances to try to insert the password.

Each time the user inserts a wrong password, show her/him one of these hints to help her/him to insert a correct password.

§ Hint 1(for the first wrong attempt) find the length of the password and print the length as a hint: “the length of your password is ….”

§ Hint 2: find how many numbers are included in the password string, and print it as the second hint: “Your password is included ...… Number letters.”

§ Hint 3: Find the total number of letter ‘i’, and print it as the third hint. “Your password is included ...… ‘i’ letter.”

Part a) Write this program using while and break statements.

Part b) Write this program using for and break statements.

Explanation / Answer

Code:

import os
import sys

nos ="0123456789"
pwd=“as1987Jantu35*^ft$TTTdyuHi28Mary”.
st=input("guess the password")
i=1
length =len(pwd)
noscount=0
counti=0
for i in range(len(pwd)):
   if pwd[i] in nos:
       noscount+=1
   if pwd[i]=='i' orpwd[i]=='I':
       counti+=1
      

while True:
   if st!=pwd and i==1:
       print "length of password is: "+len(pwd)
   if st!=pwd and i==2:
       print "Total numbers in password is: "+noscount
   if st!=pwd and i==3:
       print "Total i's in password is: "+counti      
   st=input("guess the password")
   i+=1
   if(i==4):
       break

for i in range(1,3):
   if st!=pwd and i==1:
       print "length of password is: "+len(pwd)
   if st!=pwd and i==2:
       print "Total numbers in password is: "+noscount
   if st!=pwd and i==3:
       print "Total i's in password is: "+counti      
   st=input("guess the password")
   i+=1
   if(i==4):
       break