这是我第一次来到这个网站!我真的需要帮助修复这个函数,因为我是Python新手。我对“main_function()”中的所有这些语句都感到迷茫(我甚至不知道是否需要所有这些语句)。到目前为止,我的情况是:
# X = insert(n, X, g) - syntax
# example below:
# n both of these are X
# insert(['Dmitar', 52], [ ['Kane', 32], ['Arnold', 42] ], 0)
# [['Dmitar', 52], ['Kane', 32], ['Arnold', 42]]
# insert(['Dmitar', 52], [ ['Kane', 32], ['Arnold', 42] ], 1)
#[['Kane', 32], ['Arnold', 42], ['Dmitar', 52]]
# g = 0 --> [ n + X ]
# g = 1 --> [ X + n]
def insert(n, X, g):
if g == 0:
X.insert(0, n)
else:
X.append(n)
return X
# average = avg(X) - syntax
# returns average marks
def avg(X):
X = []
average = float(sum(X))/len(X)
return X
def main_function():
X = []
# X = insert(n, X, g)
# average = avg(X)
while True:
question = input("\nPress 's' to start with new list or 'q' to quit: ").lower()
if question == 's':
qurstion = input("\nInsert members into list by name ('n') or by marks ('m'): ").lower()
# 'n' = if picked, list is ordered by name first
# 's' = if picked, list is ordered by marks first
if question == 'n':
name = input("Name: ")
marks = input("Marks: ")
break
X.append(question.title())
print("X: ", X)
#else:
#break
# I really do not know where to go from here
这就是我想要的输出类型:
Press 's' to start with new list or 'q' to quit: s
Insert members into list by name ('n') or by marks ('m'): n
Name: samantha
Marks: 45
X: [['Samantha', 45]]
Name: billy
Marks: 30
X: [['Billy', 30], ['Samantha', 45]]
Name: rudy
Marks: 75
X: [['Billy', 30], ['Rudy', 75], ['Samantha', 45]]
Name:
AVERAGE:
Billy has a mark of: 30
Rudy has a mark of: 75
Samantha has a mark of: 45
Average: 50.0
提前感谢您的帮助!你知道吗
我同意狄克的观点,字典是更好的方法。你知道吗
输出:
相关问题 更多 >
编程相关推荐