In: Computer Science
I'm making a python program that checks the users input. If the users input does not match the rules then the program will output "No". If the users input does match the rules it will output "Yes".
The rules are :
5 uppercase letters
5 lowercase letters
5 numbers
First letter must be capitilized
The total characters must be 15
I have managed to meet these conditions in individual python files but not in one. Ideally without importing anything, still learning the basics as you can see! Thanks
PYTHON CODE:
# variable to store the uppercase count
upper_case=0
# variable to store the lowercase count
lower_case=0
# variable to store the number count
numbers = 0
# flag to store first letter capital or not
firstletter=False
# getting the user input
word=input('Enter a string: ')
# getting the length of the word
length =len(word)
# looping through every character in the word
for c in word:
# if the character is upper,increment the
upper_case by 1
if c.isupper():
upper_case+=1
# if the character is lower,increment the
lower_case by 1
if c.islower():
lower_case+=1
# if the character is digit,increment the
numbers by 1
if c.isdigit():
numbers+=1
# checking the first character uppercase or not
if word[0].isupper():
firstletter=True
# checking the gives rules
if length == 15 and firstletter and upper_case==5 and lower_case
==5 and numbers ==5:
# if all the rules are satisfied, print
"Yes"
print('Yes')
else:
# otherwise, print "No"
print("No")
SCREENSHOT FOR CODING:
SCREENSHOT FOR OUTPUT: