I am a total newbie, thus I must apologize for this dumb question. But why doesn't my function return anything??
def correct_sentence(some_sent):
list_of_big = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
list_of_small = list("abcdefghijklmnopqrstuvwxyz")
list_of_sent = list(str(some_sent))
if list_of_sent[len(list_of_sent)-1] != ".":
list_of_sent.append(".")
if list_of_sent[0] in list_of_small:
for i in range(26):
if list_of_small[i] == list_of_sent[0]:
the_index = i
list_of_sent[0] = list_of_big[the_index]
new_str = "".join(list_of_sent)
return new_str
correct_sentence(input())
答案 0 :(得分:1)
It does return something, maybe you are wondering why it doesnt print something? To try that you can try to type print(correct_sentence(input())) instead at the end
答案 1 :(得分:0)
You asked why your function does not return anything. It does return, actually, you just do not know. To know if it is returning the value, try to print it. So:
print(correct_sentence(input())
Changing your code to this will make the code print the returned value.
答案 2 :(得分:-1)
This is not really a direct answer to your question, but here's what you should have done to "correct" a sentence:
def correct_sentence(some_sent):
uppercased = some_sent[0].upper() + some_sent[1:].strip()
if not uppercased.endswith("."):
uppercased += "."
return uppercased
(The function acts oddly if a sentence ends with a non-period punctuation, but hopefully you can handle it on your own.)