Oct-11-2023, 06:09 PM
Here's a short program:
Actually, I guess main() is a function defined to contain the main function so no mystery there. What is this __name__, though?
Thanks!
lwords = ["a", "an", "and", "as", "at", "but", "for", "how", "if", "in", "of", "off", "nor", "or", "so", "the", "to", "up", "via", "with", "yet"]
def make_title(sT):
rlist = []
rs = ""
for word in sT.split():
if not word.isupper() and word not in lwords:
word = word.title()
rlist.append(word)
if not rlist[0].isupper():
rlist[0].title()
if not rlist[-1].isupper():
rlist[-1] = rlist[-1].title()
for word in rlist:
rs += " " + word
rs = rs.strip()
return rs
def main():
sT = input("Enter the title: ")
print(make_title(sT))
if __name__ == "__main__": #infinite loop results with L26 and L27 uncommented.
main()I can follow the logic until the last two lines. What do __name__ and __main__ do with regard to [this] function[s]? Actually, I guess main() is a function defined to contain the main function so no mystery there. What is this __name__, though?
Thanks!
