【发布时间】:2023-09-18 16:43:02
【问题描述】:
print'Personal information, journal and more to come'
while True:
x = raw_input()
if x =="personal information":
print' Edward , Height: 5,10 , EYES: brown , STATE: IL TOWN: , SS:'
elif x =="journal":
print'would you like you open a journal or create a new one? open or create'
if x =='createfile':
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()
elif x =='openfile':
print'what file would you like to open'
y = raw_input()
read = open(y , 'r')
name = read.readline()
print (name)
break
每次我尝试运行程序时,它都会告诉我 break 已超出循环,但我不知道我还能在哪里设置 break。还有什么是记住在循环末尾放置中断的好方法?
【问题讨论】:
-
爱德华,我看过你之前的一些问题,我想问一下。您是否学习过任何基本的 Python 教程?缩进似乎很麻烦,这是python中一个非常的基本概念。
-
这不是一个坏问题。这是一个关于非常基本的误解的基本问题,但它并不不清楚或不恰当,那么为什么它被否决了?
-
我已经完成了一个基本的 Python 课程,但是我仍然在缩进方面遇到了很多麻烦,也许这个教程很糟糕,你有一个关于缩进的好教程吗?
-
@JasonFruit:试试看这里的风格指南:python.org/dev/peps/pep-0008。我建议使用 IDE 或类似 vim 的工具,这样您就可以设置自动缩进。
-
我建议你从非常简单的脚本开始,缩进一些东西......看看当你改变缩进时情况如何:)