Python 批改任务
在我尝试添加或更改以下代码(未成功)以使其正常工作后,我现在尝试从你们那里获得帮助。这是一个python新手的作品,但不幸的是,我也是,我不知道如何让它工作。我所使用的文献,没有我可以使用的相同的例子。向你们大家问好Python 批改任务,python,dictionary,Python,Dictionary,在我尝试添加或更改以下代码(未成功)以使其正常工作后,我现在尝试从你们那里获得帮助。这是一个python新手的作品,但不幸的是,我也是,我不知道如何让它工作。我所使用的文献,没有我可以使用的相同的例子。向你们大家问好 def fun (arg0 , arg ): fun1 = None for i in arg : if i not in ' aeiouAEIOU ': fun1 += 1 fun2 {i} = 1 fun3 =+ i re
def fun (arg0 , arg ):
fun1 = None
for i in arg :
if i not in ' aeiouAEIOU ':
fun1 += 1
fun2 {i} = 1
fun3 =+ i
return [ fun1 fun2 fun3 ]
def morefun ( arrg ):
e, o, u = fun ( arrg )
print ('here : ', u)
print ('here , too : ', e)
o = list (o); o. sort ()
for n in o:
print n, end =' - '
print
par = 'Was it a car or a cat I saw ?'
morefun ( par )
因此,我修复了代码并获得了输出(以我解释它的方式)。 这更是出于好奇
def fun (arg ):
fun1 = 0
fun2 = {}
fun3 = ""
for i in arg :
if i not in ' aeiouAEIOU ':
fun1 += 1
fun2[i] = fun2.get(i, 0) + 1
fun3 += i
return fun1, fun2, fun3
def morefun ( arrg ):
e, o, u = fun ( arrg )
print ('here : ', u)
print ('here , too : ', e)
o = list (o)
o. sort ()
for n in o:
print(n, end =' - ')
print
par = 'Was it a car or a cat I saw ?'
morefun ( par )
输出:
here : Wstcrrctsw?
here , too : 11
? - W - c - r - s - t - w -
正如前面提到的代码所做的:
1.打印不带元音和空格的字符串
2.打印字符串的长度
3.按字母顺序(Ascii)打印所有字母,字母之间带“-”
一些评论:
你至少知道你想做什么/实现什么吗?不,这也是理解的一个大问题。另外,试着找出剧本应该做什么“对不起,我没能找到你。”。如果您不知道要做什么,为什么要执行此任务?您不能像添加
None
和int
对象那样添加fun1+=1
。此外,在定义变量之前,您不能将其添加到变量中:fun3=+i
更清晰!。好的,您的代码包含一些无效的语法、缩进问题等。请尝试学习一些python基础知识并尝试理解您的代码。然后,您将能够清除一些错误。以后,你可以要求那些你可以自己解决的问题。