как цикл ввода (см. мой код, и вы поймете) - PullRequest
0 голосов
/ 15 октября 2019

Я хочу, чтобы мой код принимал ввод, ввод не останавливался до тех пор, пока я не введу пустую строку, и таблица будет печатать в окончательном выводе, в котором будут храниться все вводы до

, это мой код:

# read file and store in file variable
file = open("Stop Word.txt", "r")

 # create global array
 lists = []  

 # create header 
 def startingProgram():
    print("=" * 70)
    print("Masukkan Pesan: (untuk berhenti masukkan string kosong)")
    print("=" * 70)

# clean punctuation and conjunction
def message(userInput):
    punctuation = "!@#$%^&*()_+<>?:.,;/"
    words = userInput.lower().split()
    conjunction = file.read().split("\n")
    removePunc = [char.strip(punctuation) for char in words if char not in conjunction]
    global lists
    lists = removePunc
    return removePunc

# sort and count duplicate string
def counting(words):
    w_unq = sorted(((item, words.count(item)) for item in set(words)), key=lambda x: x[1], reverse=True)
    count = 1
    for u in w_unq:
        print("{}\t{:<10}\t{:<0}".format(count,*u))
        count += 1

# create table
def table():
    print("Distribusi Frekuensi Kata: ")
    print("-"*70)
    print("{}\t{:<10}\t{:<0}".format("No","Kata","Frekuensi"))
    print("-"*70)

# run program
startingProgram()
pesan = None
while pesan != "":
    pesan = input("Pesan: ")
    message(pesan)
    table()
    counting(lists)

я не знаю, как зациклить программу #run

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...