Break在循环python之外

Break在循环python之外

本文介绍了Break在循环python之外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

while True:
    x = raw_input()
    if x =="personal information":
         print' Edward , Height: 5,10 , EYES: brown , STATE: IL TOWN:  , SS:'
    elif x =="journal":
         name_of_file = raw_input("What is the name of the file: ")
         completeName = "C:\\python\\" + name_of_file + ".txt"
         file1 = open(completeName , "w")
         toFile = raw_input("Write what you want into the field")
         file1.write(toFile)
         file1.close()
else:
 break

脚本继续给我一个错误,说中断是在循环之外是缩进错误了吗?

the script keeps on giving me an error saying break is outside the loop are the indentations wrong?

推荐答案

是的,看看你的帖子。您的 else 可能与 if 语句的缩进级别一致。

Yes, look at your post. Your else probably is meant to go with the if statement's indentation level.

else 的语句,而语句完全不同。

这篇关于Break在循环python之外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 03:23