Question

In: Computer Science

In Python Please Samwell Tarly knows that in the world of Westeros, some names are better...

In Python Please
Samwell Tarly knows that in the world of Westeros, some names are better than others. Some like Aegon Targaryen and Tyrion Lannister. He and Citadel believe that a correct name should have the same number of capital letters as words, for example: Bran Stark is correct. Whereas Brienne of Tarth is not. Your task is to help read the books and determine the correct names. Each name is strictly composed of letters and names separated by single spaces. Input Format Several test cases, one per line, each containing the name of a person. No name contains more than 20 words and each word does not contain more than 30 characters. (End of file loop) Constraints (End of file loop)

Output Format For each name, you must print “Correct” if the name is approved, otherwise you must print “No”. Sample Input 0

Robert Baratheon

Daenerys Targaryen

Cersei lannister

Theon Greyjoy

Brienne of Tarth

Arya Stark

Melisandre

Gray worm

Jon snow

Daario NaHaris

Solutions

Expert Solution

CODE -

# Open file for reading

file = open("names.txt")

# Read names in the file line by line

for name in file:

    # Count no. of words in the name

    noOfWords = len(name.split())

    # Initialize the no. of uppercase characters in the name with 0

    noOfUpper = 0

    # Loop to count no. of uppercase characters in the name

    for letter in name:

        if letter >= 'A' and letter <= 'Z':

            noOfUpper += 1

    # Print "Correct" if no of capital letters in name is equal to no of words

    if noOfUpper == noOfWords:

        print("Correct")

    # Print "No" if no of capital letters in name is not equal to no of words

    else:

        print("No")

SCREENSHOTS -

INPUT TEXT FILE -

CODE WITH OUTPUT -

If you have any doubt regarding the solution, then do comment.
Do upvote.


Related Solutions

a.Why are some networks better than others to change the world in the direction of the...
a.Why are some networks better than others to change the world in the direction of the collective preferences of their members? b. Briefly identify and discuss the ten factors that impact emergence and effectiveness of global networks
using python #You've been sent a list of names. Unfortunately, the names #come in two different...
using python #You've been sent a list of names. Unfortunately, the names #come in two different formats: # #First Middle Last #Last, First Middle # #You want the entire list to be the same. For this problem, #we'll say you want the entire list to be Last, First Middle. # #Write a function called name_refixer. name_refixer should have two #parameters: an output filename (the first parameter) and the #input filename (the second parameter). You may assume that every #line will...
Write a program in python to read from a file the names and grades of a...
Write a program in python to read from a file the names and grades of a class of students to calculate the class average, the maximum, and the minimum grades. The program should then write the names and grades on a new file identifying the students who passed and the students who failed. The program should consist of the following functions: a) Develop a getGrades() function that reads data from a file and stores it and returns it as a...
Please provide some real-world (numerical if possible) examples of outsourcing.
Please provide some real-world (numerical if possible) examples of outsourcing.
As CEO of Ocean World​, Rita Greenwood knows it is important to control costs and to...
As CEO of Ocean World​, Rita Greenwood knows it is important to control costs and to respond quickly to changes in the highly competitive​ boat-building industry. When DMG Consulting proposes that Ocean World invest in an ERP​ system, she forms a team to evaluate the​ proposal: the plant​ engineer, the plant​ foreman, the systems​ specialist, the human resources​ director, the marketing director, and the management accountant. A month​ later, management accountant Marcus Chumura reports that the team and DMG estimate...
Python problem: An insurance salesperson knows the following about a client: The year the client was...
Python problem: An insurance salesperson knows the following about a client: The year the client was born. The age the client wants to retire. The annual amount the client can contribute to an IRA. The insurance agent wants to know the following: The number of years until the client retires. The number of years until the client is required to take Required Minimum Distributions. The balance of the IRA at the age the client wants to retire. The balance of...
Who knows to do this topic with python code? Write a program to perform the following...
Who knows to do this topic with python code? Write a program to perform the following two tasks: 1. The program will accept a string as input in which all of the words are run together, but the first character of each word is uppercase. Convert the string to a string in which the words are separated by spaces and only the first word starts with an uppercase letter. For example, the string "StopAndSmellTheRose" would be converted to "Stop and...
Using LIST and FUNCTION Write a program in Python that asks for the names of three...
Using LIST and FUNCTION Write a program in Python that asks for the names of three runners and the time it took each of them to finish a race. The program should display who came in first, second, and third place.
Write a python program to read from a file the names and grades of a class...
Write a python program to read from a file the names and grades of a class of students to calculate the class average, the maximum, and the minimum grades. The program should then write the names and grades on a new file identifying the students who passed and the students who failed. The program should consist of the following functions: a) Develop a gradesInput() function that reads data from a file and stores it and returns it as a dictionary....
WK 3-2 Please provide examples for better understanding discuss some of the pros and cons of...
WK 3-2 Please provide examples for better understanding discuss some of the pros and cons of outsourcing. Do you think many organizations are experiencing an increase or decrease in their levels of outsourcing? Why?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT