Function 功能和参数是测验的一部分
如果您正在显示测验问题和答案,将显示什么: 函数名: 所需参数: 返回: 需要的局部变量:Function 功能和参数是测验的一部分,function,Function,如果您正在显示测验问题和答案,将显示什么: 函数名: 所需参数: 返回: 需要的局部变量: 功能说明您使用的是哪种语言?如果你能告诉我,我可以给你举个例子 函数名通常描述函数正在执行的操作。在示例中,gradeTest()为测试打分 参数是从函数外部传递到函数中的内容。成绩测试(回答一,回答二) 编辑: answerKey = ["air","water", "london"] testTaker = input("What is your name?") ''' def adminQui
功能说明您使用的是哪种语言?如果你能告诉我,我可以给你举个例子 函数名通常描述函数正在执行的操作。在示例中,gradeTest()为测试打分 参数是从函数外部传递到函数中的内容。成绩测试(回答一,回答二) 编辑:
answerKey = ["air","water", "london"]
testTaker = input("What is your name?")
'''
def adminQuiz(name, answers): is an example of a function that administers a quiz.
The quiz takes two parameter the name of the test taker and the answer key.
testTaker -> name
answerKey -> answers
'''
def adminQuiz(name, answers):
# Welcome message to the test taker
print ("Welcome to the Quiz " + name + "! Lets begin!")
# answers are assigned to local variables inside this function and used to compare to the correct answers from the key
#
# Question I
responseOne = input("What do you breath?")
if (answers[0] == responseOne):
print ("You answered " + responseOne + " and that is correct.")
else:
print ("You answered " + responseOne + " and that is not correct." + " The correct answer is " + answers[0])
# Question II
responseTwo = input("What is the ocean made of?")
if (answers[1] == responseTwo):
print ("You answered " + responseTwo + " and that is correct.")
else:
print ("You answered " + responseOne + " and that is not correct." + " The correct answer is " + answers[1])
# Question III
responseThree = input("What is the capital of the United Kingdom?")
if (answers[2] == responseThree):
print ("You answered " + responseThree + " and that is correct.")
else:
print ("You answered " + responseThree + " and that is not correct." + " The correct answer is " + answers[2])
# return statement to complete function and let user know the quiz is over.
return "We've completed the quiz!"
quiz = adminQuiz(testTaker, answerKey)
print (quiz)
'''
Function name: adminQuiz
Parameters needed: name, answers
Returned: a message declaring the quiz is over
Local variables needed: labels for user input ex. responseOne, responseTwo, responseThree
Description of function:
A function is a block of organized, reusable code that is used to perform a single related action.
'''
您可以在此处尝试此示例:
嗨,对不起,我正在使用python@JadeM我已经发布了最新消息。如果我能澄清任何部分,请不要犹豫!