我正在写一个程序,该程序应该按照输入行读取,直到输入空行。如果这条线开始与西蒙说,它应该打印出该行的其余部分。不以Simon开头的线应该被忽略。所以我无法写程序,因为它需要像这样的输出:Python语句打印错误
Enter: jump
Enter: Simon says shout loudly
shout loudly
Enter: simon would like you to eat a frog
Enter: Simon says clap your hands
clap your hands
Enter:
和我生产的代码是这样的:
forever (while True) do the following:
input a sentence
if its length is 0: break
else if it starts with 'Simon says':
print sentence from the n-th character (sentence[n:]),
where n is the length of the string 'Simon says'
丹尼尔有一个在输出 – rocker789
来了一个空间@ rocker789是因为'replace'只替换你告诉它的子字符串,而不是紧接它后面的空格 - 如果你想摆脱这个空间并且把它包含在'replace'的调用中,就像'word'一样。取代('Simon说','')'。 – lvc