除getValue函数工作外,我得到了一切。系统会提示输入正整数,负整数,48-122之间的一个整数和一个字符串。一旦我将它们全部输入,我希望它能重印它们,除了显示的abs,chr和len函数。这是我得到语法错误的地方。如何获得打印以重印输入,但使用abs,chr,len函数?
def main():
posInteger()
negInteger()
myChar()
myString()
getValues()
def posInteger():
#Declaring positive integer value
posInt = (input('Enter a positive integer: ')
def negInteger():
#Declaring negative integer value
negInt = input('Enter a negative integer:')
def myChar():
#Declaring integer
myCh = input('Enter an integer between 48 and 122 incluseive: ')
def myString():
#Declaring string
myStr = input('Enter a string: ')
def getValues():
#Prints the variables back out to user
print ('The positive int is,', abs(posInt))
print('textbody', abs(negInt))
print('textbody', chr(myCh))
print('textbody', len(myStr))
#raiser posInt by power 4
main()
编辑:
这是我的程序在运行时的外观(W /错误)
Enter a positive integer: 45
Enter a negative integer:-1
Enter an integer between 48 and 122 incluseive: 90
Enter a string: daf
Traceback (most recent call last):
File "D:\.Drexel Affil\info\info108\W3\scrap.py", line 38, in <module>
main()
File "D:\.Drexel Affil\info\info108\W3\scrap.py", line 7, in main
getValues()
File "D:\.Drexel Affil\info\info108\W3\scrap.py", line 32, in getValues
print('The positive int is,', abs(posInt))
TypeError: bad operand type for abs(): 'str'
什么是错误您收到?请[编辑]你的问题,并添加错误的**全文**。另外,你在'posInt =(input('输入一个正整数:')'行缺少一个结束''''。你不需要最初的'(',所以只需要清除它) – MattDMo
@ MattDMo如果你阅读代码,错误是显而易见的 – orlp
@orlp我已经阅读了代码,并且对错误是什么有我的想法,但是我想要OP仔细阅读错误,仔细想想,并且可能发现“教一个人钓鱼......”等等 – MattDMo