# title = "Alice in Wonderland"# print(title.split()) def count_words(filename): ‘‘‘ count how many words in a text file ‘‘‘ try: with open(filename) as f_obj: contents = f_obj.read() except FileNotFoundError: pass #msg = "Sorry, the file " + filename + " does not exist." #print(msg) else: words = contents.split() print("The file " + filename + " has about " + str(len(words)) + " words.") def addTwoNumber(): ‘‘‘ add two numbers. ‘‘‘ first_number = input("First Number: ") second_number = input("Second Number: ") try: first_number = int(first_number) second_number = int(second_number) except ValueError: print("Please check if your input is legal.") return False else: res = first_number + second_number print(str(first_number)+" + "+str(second_number)+" is "+str(res)) return True
原文地址:https://www.cnblogs.com/QiLF/p/9231787.html
时间: 2024-11-11 02:46:26