标签:sha 而不是 文件中 一个 pen 编写 实践 str oom
[url=][/url]
print("Enter two numbers, and I‘ll add them.")first_number = input("\nFirst number: ")second_number = input("Second number: ")try: nums_sum = int(first_number) + int(second_number) print(first_number + ‘+‘ + second_number + ‘=‘ + str(nums_sum))except ValueError: print("Sorry! Only accept numbers input.")[url=][/url]
[url=][/url]
print("Enter two numbers, and I‘ll add them.")print("Enter ‘q‘ to quit.")while True: first_number = input("\nFirst number: ") if first_number == ‘q‘: break second_number = input("Second number: ") if second_number == ‘q‘: break try: nums_sum = int(first_number) + int(second_number) print(first_number + ‘+‘ + second_number + ‘=‘ + str(nums_sum)) except ValueError: print("Sorry! Only accept numbers input.")[url=][/url]
[url=][/url]
file_names = [‘cats.txt‘, ‘dogs.txt‘]for filename in file_names: try: with open(filename) as f_obj: names = f_obj.read() print(filename + " include:\n" + names.rstrip()) except FileNotFoundError: print("Sorry, the file " + filename + " can not fond.")[url=]
[/url]
[url=]
[/url]
file_names = [‘cats.txt‘, ‘dogs.txt‘]for filename in file_names: try: with open(filename) as f_obj: names = f_obj.read() print(filename + " include:\n" + names.rstrip()) except FileNotFoundError: pass[url=]
[/url]
更多技术资讯可关注:gzitcast
标签:sha 而不是 文件中 一个 pen 编写 实践 str oom
原文地址:https://www.cnblogs.com/heimaguangzhou/p/11775083.html