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
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...
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.
Please provide some real-world (numerical if possible) examples of outsourcing.
Please provide some real-world (numerical if possible) examples of outsourcing.
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...
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...
THIS IS A PYTHON ASSIGNMENT 1. The following are invalid variable names: 3g, 87 and 2h....
THIS IS A PYTHON ASSIGNMENT 1. The following are invalid variable names: 3g, 87 and 2h. 2. The operator != is an example of a relational operator. 3. A variable name identifies the kind of information stored in the object. 4. Python treats the variable names, a1 and A1, as the same variable. 5. The if/else selection structure is a single-selection structure. 6 A fatal logic error causes a program to execute and produce incorrect results. 7) A repetition structure...
Write a program that uses Python List of strings to hold the five student names, a...
Write a program that uses Python List of strings to hold the five student names, a Python List of five characters to hold the five students’ letter grades, and a Python List of four floats to hold each student’s set of test scores. The program should allow the user to enter each student’s name and his or her four test scores. It should then calculate and display each student’s average test score and a letter grade based on the average....
Python A good friend of yours sent you a long list of recipe names in a...
Python A good friend of yours sent you a long list of recipe names in a text file (where each line is a recipe that also includes information about how long it takes to do the recipe). You only want to know about the recipes that involve chocolate and are fast (i.e., take 15 mins or less to prepare). Write the program for this! Write a program to -       + Find recipes that involve chocolate that can be done...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT