【发布时间】:2022-01-07 01:39:56
【问题描述】:
我被分配了一个任务,我应该通过给出函数的编号来编写执行不同类型计算/函数的程序(必须使用带有 def 的函数)。并严重坚持下去。
1.
choice = int(input("Chosen function: "))
while choice != 0
if choice == 1:
print("Sum of the list: ", summ_list(lista))
if choice == 2:
print("Is the chosen number inside?: ", decide_if_in(lista, s))
.......
else:
print("The program closes.")
如果用户按下 0,程序应该终止。但是尽我最大的努力,如果我做一段时间或 for 循环,它将陷入无限循环,因此我无法解决它。
2.
def decide_if_in():
s = int(input("Which number do you think is in the list?: "))
for d in s:
if d == s:
print("It is in the list")
else:
print("It is not in the list..")
在这里它可以在没有 def 标签的情况下工作,但我不能让它与它一起工作。重点是我给它一个数字,然后它会检查列表中的列表?
【问题讨论】:
-
请问你能更好地格式化这个问题吗?从代码中不是很清楚发生了什么
-
从 Python 和编程的基本教程开始。您尝试解决的问题将成为最初一到两百万小时学习的一部分。
-
你的python代码缩进是否正确?在 python 中,空格很重要,并从代码中定义范围块。