我对编程和Python非常陌生。该程序的目标是在输出时将用户句子显示为三角形。到目前为止我所拥有的是这个
def main():
enteredSentence = input('Enter a short sentence: ')
count = 0
return enteredSentence, count
#prints the sentence in a triangle from first letter to full sentence
def UP(enteredSentence,count):
for count in (enteredSentence):
count = count + 1
print(enteredSentence[0:count])
print(enteredSentence)
# prints the sentence in a triangle from full sentence to first letter
def Down(enteredSentence, count):
for count in enteredSentence:
count = count - 1
print(enteredSentence [0:count])
# prints out a message with the total count of letters printed.
#def Count():
main()
程序运行,但只接受输入,然后停止
最佳答案
def main():
input_sentence = input('Enter a short sentence: ')
count = 0
up(input_sentence, count)
down(input_sentence, count)
# prints the sentence in a triangle from first letter to full sentence
def up(input_sentence, count):
for letter in (input_sentence):
count += 1
print(input_sentence[0:count])
print(input_sentence)
# prints the sentence in a triangle from full sentence to first letter
def down(input_sentence, count):
for letter in input_sentence:
count -= 1
print(input_sentence[0:count])
# prints out a message with the total count of letters printed.
if __name__ == '__main__':
main()
产量:
$ Enter a short sentence: hello
h
he
hel
hell
hello
hello
hell
hel
he
h
我让代码更加“Pythonic”。看看here
关于python - 我怎样才能让程序继续进行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58780511/