我卡住了,需要一些指导。我正在努力独立学习使用Grok Learning的Python。下面是问题和示例输出以及我的代码中的位置。我感激任何能帮助我解决这个问题的提示。
In linguistics, a bigram is a pair of adjacent words in a sentence. The sentence "The big red ball." has three bigrams: The big, big red, and red ball.
Write a program to read in multiple lines of input from the user, where each line is a space-separated sentence of words. Your program should then count up how many times each of the bigrams occur across all input sentences. The bigrams should be treated in a case insensitive manner by converting the input lines to lowercase. Once the user stops entering input, your program should print out each of the bigrams that appear more than once, along with their corresponding frequencies. For example:
Line: The big red ball Line: The big red ball is near the big red box Line: I am near the box Line: near the: 2 red ball: 2 the big: 3 big red: 3
我还没有很好地完成我的代码,目前遇到了困境。但是以下是我的进展:
words = set()
line = input("Line: ")
while line != '':
words.add(line)
line = input("Line: ")
我是否做对了?尽量不要导入任何模块,只使用内置功能。
谢谢, Jeff