def subtract(num):
string = str(num)
a = string[0]
b = string[1]
c = string[2]
large = max(a, b, c)
small = min(a,b,c)
summation = int(a) + int(b) + int(c)
mid = summation - int(large) - int(small)
mid2 = str(mid)
ascend = large + mid2 + small
descend = small + mid2 + large
print('The digits in ascending order are', ascend)
print('The digits in descending order are', descend)
value = int(descend) - int(ascend)
return value
def main():
dummy = input('Type a three digit integer, please.\n')
if not len(dummy) == 3:
print('Error!')
main()
elif not dummy.isdigit():
print('Error!')
main()
if len(dummy) == 3 and dummy.isdigit():
subtract(dummy)
print('The value of the digits in descending order minus the digits in ascending order is', value)
main()
내가 입력 AA 번호는 (123)처럼, 내가 얻을 때 :어떻게이 반품/글로벌 오류를 수정합니까?
Type a three digit integer, please.
123
The digits in ascending order are 321
The digits in descending order are 123
Traceback (most recent call last):
File "/Users/philvollman/Documents/NYU/Freshman /Fall Semester/Intro to Computer Programming/Assignments/Homework5PartA.py", line 29, in <module>
main()
File "/Users/philvollman/Documents/NYU/Freshman /Fall Semester/Intro to Computer Programming/Assignments/Homework5PartA.py", line 28, in main
print('The value of the digits in descending order minus the digits in ascending order is', value2)
NameError: global name 'value2' is not defined
>>>
내가 문에 해당하는 경우로 반환 된 값이해야하는 경우 내 첫 번째 기능은 실행되기 때문에 나는이 무엇입니까 왜 확실하지 않다 if 문 내에서 반환됩니다. 당신이 main
에 정의되지 않은 value
라는 이름의 변수를 참조 main
의 끝에 print
에 대한 호출에서
붙여 넣은 코드에 'value2'가 전혀 없으므로 실제로 실행중인 코드와 동일하지 않습니다. – Useless