Question

Write a python program that will analyse the string input and print “accept” or “reject” based...

Write a python program that will analyse the string input and print “accept” or “reject” based on the pattern given

Accept if it fulfils the following conditions

 String length 9  3 small alphabet (3 lowercase letter)  3 number (3 digit)  3 big alphabet (3 uppercase letters)  1 st alphabet should be capital  Last alphabet should be a number  Two consecutive alphabets can’t be small

Reject if any of the condition is absent

0 0
Add a comment Improve this question Transcribed image text
Answer #1

SOURCE CODE:

*Please follow the comments to better understand the code.

**Please look at the Screenshot below and use this code to copy-paste.

***The code in the below screenshot is neatly indented for better understanding.

def check(s):
  
#Conditions applied 1,5,6
if len(s)==9 and s[0].isupper() and s[-1].isdigit():
upper_count = sum(1 for c in s if c.isupper())
lower_count = sum(1 for c in s if c.islower())
number_count = sum(1 for c in s if c.isdigit())
  
#Conditions 2,3,4
if upper_count==3 and lower_count==3 and number_count==3:
  
#Condition 7 { Two consecutive alphabets can’t be small }
for i in range(1,len(s)):
if s[i-1].islower() and s[i].islower() :
return 'reject'
else:
return 'reject'
#All conditions satisfies here, so accept
return 'accept'
  
else:
return 'reject'
  
  
### TEST CASES ###
print(check('ABiG1h2f3')) #ALL correct


# BELOW ALL SHOULD BE REJECTED
print(check('AbiG1h2f3')) # bi consecutive two small letters

print(check('aBiG1h2f3')) # Starts with small letter

print(check('ABiG1h2fe')) # doesn't end with number

print(check('ABiG1h')) #Length is not 9

print(check('ABiG1h334')) # has 4 numbers. Also only 2 small letters

==================

SCREENSHOT:

Add a comment
Know the answer?
Add Answer to:
Write a python program that will analyse the string input and print “accept” or “reject” based...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write an LC-3 program (starting at memory location 0x3000) to take a string as input and...

    Write an LC-3 program (starting at memory location 0x3000) to take a string as input and then output information about this string. The end of the string will be denoted with the "#" character. Once the "#" has been found, output the following in order: 1) The letter “u” followed by the number of uppercase letters in the string (A-Z) 2) The letter “l” followed by the number of lowercase letters in the string (a-z) 3) The letter “n” followed...

  • in Python: •Flip case: Write a program to do the following: •Accept the input of a...

    in Python: •Flip case: Write a program to do the following: •Accept the input of a sentence from the user that contains lowercase, uppercase, and special characters. •Make a new sentence in which the lowercase characters are changed to uppercase and the uppercase are changed to lower case.   All other characters will retain their original value. Print the original sentence and the new sentence.

  • I need help with the following question Write a script based on the program in Exercise...

    I need help with the following question Write a script based on the program in Exercise 11.13 that inputs several lines of text and uses String method indexOf to determine the total number of occurrences of each letter of the alphabet in the text. Uppercase and lowercase letters should be counted together. Store the totals for each letter in an array, and print the values in tabular format in an HTML5 textarea after the totals have been determined. I need...

  • PYTHON You are to write a program that will analyze the frequency of letters in a...

    PYTHON You are to write a program that will analyze the frequency of letters in a string. The user will enter a string, your program will output the number of times the letters of the alphabet appear in that string. The user is to enter a string that has upper or lower case letters only, no spaces or other characters. You should convert the string entered to all lowercase letters before you conduct your analysis.

  • Python Write a function named letter_function. The function should accept a string (i.e., any string) and...

    Python Write a function named letter_function. The function should accept a string (i.e., any string) and display the letters in that string. For example, if the function received "python 3.2". The following letters will be displayed: (Hint: you can use s.isalpha() to know if a character is a letter) p y t h o n

  • Python: Write a program that lets the user enter a string and displays the letter that...

    Python: Write a program that lets the user enter a string and displays the letter that appears most frequently in the string, ignore spaces, punctuation, and Upper vs Lower case. Create a list to hold letters based on the length of the user input Convert all letters to the same case Use a loop to check for each letter in the alphabet Have a variable to hold the largest number of times a letter appears, and replace the value when...

  • Answer in python please and use loop Question 2: Write a program that prompts the user...

    Answer in python please and use loop Question 2: Write a program that prompts the user to enter a sentence string. The program will either print True if the sentence contains every letter of the alphabet. If the sentence does not contain each letter, print which letters are missing. The results should not depend on capitalization. Hint: a loop may be very handy in the solution.

  • Write a program that inputs a string from the user representing a password, and checks its...

    Write a program that inputs a string from the user representing a password, and checks its validity. A valid password must contain: -At least 1 lowercase letter (between 'a' and 'z') and 1 uppercase letter (between 'A' and 'Z'). -At least 1 digit (between '0' and '9' and not between 0 and 9). At least 1 special character (hint: use an else to count all the characters that are not letters or digits). -A minimum length 6 characters. -No spaces...

  • Write a program(Python language for the following three questions), with comments, to do the following:   ...

    Write a program(Python language for the following three questions), with comments, to do the following:    Ask the user to enter an alphabetic string and assign the input to a variable str1. Print str1. Check if str1 is valid, i.e. consists of only alphabetic characters. If str1 is valid Print “<str1> is a valid string.” If the first character of str1 is uppercase, print the entire string in uppercase, with a suitable message. If the first character of str1 is...

  • I need eclipse code for : Write a program that analyzes text written in the console...

    I need eclipse code for : Write a program that analyzes text written in the console by counting the number of times each of the 26 letters in the alphabet occurs. Uppercase and lowercase letters should be counted together (for example, both ‘A’ and ‘a’ should count as an A). Any characters that are not letters should be ignored. You must prompt the user to enter the text to be analyzed. Then, for any letter that appeared at least once...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT