asked 175k views
2 votes
You wrote a program to determine if a password contained a numeric character.

password = input("Password? ")
hasNumber = False
for character in password:
if character.isdigit():
hasNumber = True
break

Finish the code that is a shorter alternate.

password = input("Password? ")
valid = True
if not __ (character.isdigit() for character in password)
valid = False

2 Answers

3 votes

Here is the completed code that is a shorter alternate to the given program:


\rm \: password = input(


\rm \: valid = not \: all(character.isalpha() for \: character \: in \: password)

This code uses a generator expression within the all() function to check if all characters in the password are alphabetical. If all characters are alphabetical, the expression evaluates to True, and the not operator negates it to False, indicating that the password is not valid. If at least one character is a digit, the expression evaluates to 'False', and the 'not' operator negates it to 'True', indicating that the password is valid.

The variable valid is assigned the resulting Boolean value indicating if the password is valid or 'not'

answered
User Gisette
by
8.6k points
7 votes

Answer:

any

Step-by-step explanation:

"any" bc i got it right

answered
User Rithin Chalumuri
by
8.3k points
Welcome to Qamnty — a place to ask, share, and grow together. Join our community and get real answers from real people.