Answer to Question #276275 in Python for happpy

Question #276275

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


1
Expert's answer
2021-12-09T17:38:13-0500
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

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS