Let’s assume Sheldon Cooper gives his friends the password for entering his
house and only let them enter his house if the password is correct. This
password must contain at least one number. If the password fails to have at
least one number, print “Leave”. Then, Sheldon runs a program that sums the
ASCII values of the numbers which were found from the password.
If the summation is an even number, then the program prints “Correct, you
may enter”.
If the summation is an odd number, then the program prints “Incorrect, you
may leave”.
Write a python program that reads a string (the password) as an input from
the user, makes a list of the characters from the input string (password),
and prints the list.
Sample Input 1:
penny06nebraska
Sample Output 1:
['p', 'e', 'n', 'n', 'y', '0', '6', 'n', 'e', 'b', 'r', 'a', 's', 'k', 'a']
Correct, you may enter
password = input('Enter password here: ')
j = 0
list1 = []
list2 = []
for i in password:
list2.append(i)
if i.isdigit() == True:
list1.append(i)
j = ord(i) + j
if j % 2 == 0 and len(list1) > 0:
print(list2)
print('correct, you may enter')
else:
print('incorrect: you may leave')
Enter password here: penny06nebraska
['p', 'e', 'n', 'n', 'y', '0', '6', 'n', 'e', 'b', 'r', 'a', 's', 'k', 'a']
correct, you may enter
Comments
Leave a comment