代码:
Encode_Decode = input("Would you like to Encode, or Decode your text?")
def encode_decode_retry():
an = input('Sorry, I didn\'t understand. Would you like to Encode, or Decode your text?')
if an != "Encode" and an != "Decode":
an = ""
encode_decode_retry()
else:
print(an)
return an
if Encode_Decode != "Encode" and Encode_Decode != "Decode":
x = (encode_decode_retry())
print(x)
它打印“解码”或“编码”,但是当我返回它时,它返回“无”。我的版本是3.7
答案 0 :(得分:2)
您在if子句中缺少return语句。只需在调用函数之前添加return
def encode_decode_retry():
an = input('Sorry, I didn\'t understand. Would you like to Encode, or Decode your text?')
if an != "Encode" and an != "Decode":
an = ""
return encode_decode_retry()
else:
print(an)
return an