我无法在函数外部打印 fi 值


s= input("enter the string to be checked")
def pig(s):
first=s[0]
if first in "aeoui":
fi=s + "ay"
else:
fi=s[1:]+first+"ay"
return fi

返回fi

s= input("enter the string to be checked") 
def pig(s): 
first=s[0] 
if first in "aeoui": fi=s + "ay" 
else: fi=s[1:]+first+"ay"
return fi
fi = pig(s)
print(fi)

或 使fi成为可从任何地方访问的全局变量

s= input("enter the string to be checked") 
def pig(s): 
global fi
first=s[0] 
if first in "aeoui": fi=s + "ay" 
else: fi=s[1:]+first+"ay"
pig(s)
print(fi)

最新更新