创建一个名为 "firstletter" 的函数,它将一个字符串作为参数。然后在函数中,打印该字符串的第一个字母

Create a function called "firstletter" that takes one string as a parameter. Then in the function, print the first letter of that string

以上问题陈述我的代码是:

def firstletter(x):
    x=input()
    print(x[0])
firstletter()

但是我遇到了这个错误

Oops, your solution is incorrect.

TypeError: firstletter() missing 1 required positional argument: 'x'

谁能帮我解决这个问题。

您的函数目前不接受任何参数。下面是一些文档的 link,解释了什么是函数和函数参数。

python functions

正确答案是:

def firstletter(x):
    print(x[0])

因为编译器已经有了自定义输入,所以它只是检查函数是否传递了一个参数,以及是否使用了一个字符。

p.s.: 在 udemy 中我们无法查看是否有测试用例或自定义输入。