多次循环,直到成功:while attempt < max_attempts: try: # 尝试执行的代码 result = 1 / 0 # 这里会引发一个异常 break # 如果成功,跳出循环 except Exception as e: print(f"尝试失败,原因:{e}") attempt += 1else: print("达到最大尝试次数,仍然失败")