[Python] Need help writing python code for an assignment

Discussão em 'Python' iniciado por Stack, Março 17, 2025.

  1. Stack

    Stack Membro Participativo

    I have an assignment to and I don't understand how to do it at all. Here is the question:


    Write a program that counts and displays the number of words and the number of sentences in the following paragraph:

    A Turing machine is a device that manipulates symbols on a strip of tape according to a table of rules. Despite its simplicity, a Turing machine can be adapted to simulate the logic of any computer algorithm, and is particularly useful in explaining the functions of a CPU inside a computer. The "Turing" machine was described by Alan Turing in 1936, who called it an "a(utomatic)-machine". The Turing machine is not intended as a practical computing technology, but rather as a hypothetical device representing a computing machine. Turing machines help computer scientists understand the limits of mechanical computation.
    ​

    And here is what i have written already:

    def main():
    def word_count(str):
    counts = dict()
    words = str.split()

    for word in words:
    if word in counts:
    counts[word] +=1
    else:
    counts[word] = 1

    return counts


    Thanks

    Continue reading...

Compartilhe esta Página