如何回到python中的变量?
我用Python编写这个脚本已经有一段时间了。然而,我遇到了一个问题: 在我的代码中,用户键入一个命令,一些文本看起来有点像MS-DOS,但我不知道如何让它回到问题上来。目前节目刚刚结束 以下是我的脚本示例:如何回到python中的变量?,python,variables,Python,Variables,我用Python编写这个脚本已经有一段时间了。然而,我遇到了一个问题: 在我的代码中,用户键入一个命令,一些文本看起来有点像MS-DOS,但我不知道如何让它回到问题上来。目前节目刚刚结束 以下是我的脚本示例: command=raw_input("j;/") command1="help" command2="jver" if command==command1: print "List of commands" print"" print"" print
command=raw_input("j;/")
command1="help"
command2="jver"
if command==command1:
print "List of commands"
print""
print""
print"help = shows all commands"
print ""
print "jver = Version of MS-Josh"
#Code here so that it goes back to the j;/ raw_input question.
elif command==command2:
print "MS-Josh version 3.12."
print ""
print "memory used: 7,117 bytes"
print "memory on computer: 1,434,078 bytes"
print "memory free: 1,426,961"
#Code here so that it goes back to the j;/ raw_input question.
else:
print "incorrect command"
也许你想要:
while True:
...
如果将语句放在脚本的顶部,这将使您回到顶部
像这样:
while True:
command=raw_input("j;/")
command1="help"
command2="jver"
if command==command1:
print "List of commands"
print""
print""
print"help = shows all commands"
print ""
print "jver = Version of MS-Josh"
elif command==command2:
print "MS-Josh version 3.12."
print ""
print "memory used: 7,117 bytes"
print "memory on computer: 1,434,078 bytes"
print "memory free: 1,426,961"
else:
print "incorrect command"
使用迭代循环您的命令,并为用户提供退出的方式
while True:
command=raw_input("j;/")
command1="help"
command2="jver"
command3='end'
if command == command3:
return
elif command==command1:
...... your code
你能举个例子吗?用户输入->你期望什么?你正在寻找循环和函数-这些应该包含在任何编程入门或初学者教程中,所以我建议你去读一本。StackOverflow不是一个旨在教你绝对编程基础知识的网站;请阅读,不要问离题的问题。。。