菜单驱动程序,用于打印其他程序



我已经为菜单驱动程序编写了一段代码,但在输入代码后,菜单就不会打印了。请帮帮我!

这是代码-

def mainMenu():
print("1. lst")
print("2. a")
print("3. quit")
while True:
selection=int(input("Enter Choice: "))
if selection==1:
lst()
elif selection==2:
a()
elif selection==3:
exit
else:
print("Invalid choice. Enter 1-3")
mainMenu()

def lst():
lst = []
num = int(input("How many numbers: "))
for n in range(num):
numbers = int(input("Enter the numbers"))
lst.append(numbers)
print("Maximum element in the list is :", max(lst), "nMinimum element in the list is :", min(lst))

主菜单((

def a():
a=[]
n=int(input("Enter number of elements"))
for i in range (1, n+1):
b=int(input("Enter element:"))
a.append(b)
a.sort()
print("Third largest element is:",a[n-3])`

主菜单((

您需要对缩进进行排序。

def mainMenu():
print("1. lst")
print("2. a")
print("3. quit")
while True:
selection=int(input("Enter Choice: "))
if selection==1:
lst()
elif selection==2:
a()
elif selection==3:
exit()
else:
print("Invalid choice. Enter 1-3")
mainMenu()  # Also watch for recursion here

和你的第二部分

def lst():
lst = []
num = int(input("How many numbers: "))
for n in range(num):
numbers = int(input("Enter the numbers"))
lst.append(numbers)
print("Maximum element in the list is :", max(lst), "nMinimum element in the list is :", min(lst))

运行以下代码

def lst():
lst = []
num = int(input("How many numbers: "))
for n in range(num):
numbers = int(input("Enter the numbers"))
lst.append(numbers)
print("Maximum element in the list is :", max(lst), "nMinimum element in the list is :", min(lst))
def mainMenu():
print("1. lst")
print("2. a")
print("3. quit")
while True:
selection=int(input("Enter Choice: "))
if selection==1:
lst()
elif selection==2:
a()
elif selection==3:
exit()
else:
print("Invalid choice. Enter 1-3")
mainMenu()  # Also watch for recursion here
mainMenu()

创建该输出

1. lst
2. a
3. quit
Enter Choice: 1
How many numbers: 5
Enter the numbers1
Enter the numbers2
Enter the numbers3
Enter the numbers4
Enter the numbers5
Maximum element in the list is : 5 
Minimum element in the list is : 1
Enter Choice: ^C

相关内容

最新更新