Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- '''Example of a while loop
- Only 1 user: 'mark' with password 'spoon'
- '''
- def rec_pass(password, tries):
- '''checks password for a number of tries'''
- if password == 'spoon':
- return 1
- elif tries == 1:
- return 0
- else:
- return rec_pass(input('Enter Password: '), tries-1)
- def _main():
- exit_flag = 1
- while exit_flag == 1:
- username = input('Enter username: ')
- if username == 'mark':
- print('O Hai! {}!'.format(username))
- else:
- print('Unknown User!')
- continue
- access = rec_pass(input('Enter Password: '), 3)
- if access == 1:
- print('Access Granted')
- break
- else:
- print('Max retries reached')
- exit_flag = 0
- else:
- print('Invalid Password! Program Terminated')
- if __name__ == '__main__':
- _main()
Add Comment
Please, Sign In to add comment