【发布时间】:2017-01-05 09:02:30
【问题描述】:
我想知道是否有办法将数学符号添加到函数参数中。
def math(x, y, symbol):
answer = x 'symbol' y
return answer
这是我的意思的一个小例子。
编辑: 这是整个问题
def code_message(str_val, str_val2, symbol1, symbol2):
for char in str_val:
while char.isalpha() == True:
code = int(ord(char))
if code < ord('Z'):
code symbol1= key
str_val2 += str(chr(code))
elif code > ord('z'):
code symbol1= key
str_val2 += str(chr(code))
elif code > ord('A'):
code symbol2= key
str_val2 += str(chr(code))
elif code < ord('a'):
code symbol2= key
str_val2 += str(chr(code))
break
if char.isalpha() == False:
str_val2 += char
return str_val2
我需要多次调用该函数,但有时使用 +/- 表示第一个符号,有时使用 +/- 表示第二个符号
原始代码:
def code_message(str_val, str_val2):
for char in str_val:
while char.isalpha() == True:
code = int(ord(char))
if code < ord('Z'):
code -= key
str_val2 += str(chr(code))
elif code > ord('z'):
code -= key
str_val2 += str(chr(code))
elif code > ord('A'):
code += key
str_val2 += str(chr(code))
elif code < ord('a'):
code += key
str_val2 += str(chr(code))
break
if char.isalpha() == False:
str_val2 += char
return str_val2
【问题讨论】:
-
抱歉,您能详细说明一下吗
-
你的意思是
answer = x "symbol" y?
标签: python function math symbols sign