【发布时间】:2020-09-04 21:03:12
【问题描述】:
我正在学习 Python,我想创建一个输入数字的简单菜单。 当我运行脚本时,我的控制台只会给我这个错误。有关如何解决此问题的任何提示? 我正在用原子编码这个。它在我添加 menu() 之前运行,只是将它作为普通的 print() 语句。但我想在以后添加更多横幅和东西,只是认为在代码中调用函数比到处都有打印语句更漂亮。
Process returned 0 (0x0) execution time : 0.060 s Press any key to continue . . .
这是我的代码 =)
#!/usr/bin/env python
# Imports
import os
from time import sleep
#Definitions
def menu():
print('''{0}
_________________________________________________________________________________
{1}
| [MAIN MENUE] |
| [1] Option 1 |
| [2] Option 2 |
| [3] Option 3 |
| [4] Option 4 | {0}
_________________________________________________________________________________
'''.format(PURPLE, BLUE))
clear = lambda: os.system('cls') #on Windows System
PURPLE = '\033[95m'
BLUE = '\033[94m'
GREEN = '\033[92m'
OCRA = '\033[93m'
RED = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
#Start of Menu
def mainMenu():
while True:
try:
menu()
selection = input('{0}[>]Please input your module of choice: '.format(BLUE))
if selection == '1':
print("{0}[+] You have chosen module 1".format(PURPLE))
sleep(1.5)
elif selection == '2':
print("{0}[+] You have chosen module 2".format(PURPLE))
sleep(1.5)
elif selection == '3':
print("{0}[+] You have chosen module 3".format(PURPLE))
sleep(1.5)
elif selection == '4':
print("{0}[+] You have chosen module 4".format(PURPLE))
sleep(1.5)
else:
print("{0}[-] Whoopsie, this module does not exist, try another".format(RED))
sleep(1.5)
clear()
mainMenu()
except ValueError:
os.system("pause")
【问题讨论】:
标签: python python-3.x process scripting