python - 如何在python中的命令上使程序重新启动
问题描述
我有以下程序:
x = int(input('How many rows? - '))
y = int(input('How many max per row? - '))
z = int(input('How many min per row - '))
string = str('•')
lines = y # Makes a copy of y that can be seperatly changed
while True:
if z > y: # Makes sure than "max per row" > "min per row"
print('Please make sure that \"max per row\" is greater than \"min per row\"')
break
for n in range(int(x)): # Run the specified amount of times
if int(lines) > int(z): # If 'max per row' < 'min per row'
for more in range(int(y)): # Print '•'*'y' untill it reaches 'min per row'
print(str(string)*int(lines))
lines -= 1
else:
for less in range(int(y)): # Print '•'*'y' untill it reaches 'max per row'
print(str(string)*int(lines))
lines += 1
我要restart
程序if z > y
。目前我用一个函数停止程序break
,我希望它能够re-run
. (见第 12 行)
解决方案
你可以创建一个函数
def main():
x = int(input('How many rows? - '))
y = int(input('How many max per row? - '))
z = int(input('How many min per row - '))
string = str('•')
lines = y # Makes a copy of y that can be seperatly changed
while True:
if z > y: # Makes sure than "max per row" > "min per row"
print('Please make sure that \"max per row\" is greater than \"min per row\"')
break
for n in range(int(x)): # Run the specified amount of times
if int(lines) > int(z): # If 'max per row' < 'min per row'
for more in range(int(y)): # Print '•'*'y' untill it reaches 'min per row'
print(str(string)*int(lines))
lines -= 1
else:
for less in range(int(y)): # Print '•'*'y' untill it reaches 'max per row'
print(str(string)*int(lines))
lines += 1
while True:
main()
推荐阅读
- javascript - Vue中用于小部件非导入组件的未知自定义元素元素
- javascript - 如何在某些坐标(Webdriver io)上进行 doubleClick()?
- flutter - 使用颤振的 Listview 上没有显示来自服务器 API 的数据
- javascript - Gatsby 与 Typescript 是否使用 tsconfig.json
- excel - 如何在 Excel 的其他单元格中找到索引详细信息中的单元格值
- python - How to revert Mocking
- gitlab - Gitlab:已批准的合并请求仍显示需要合并的消息
- python - PyQt:无法使用 QTabWidget 实现 QSizePolicy.Minimum
- amazon-web-services - AWS lambda 是否必须使用 cloudwatch?
- excel - VBA 条件格式 - 添加表达式