• 카테고리

    질문 & 답변
  • 세부 분야

    프로그래밍 언어

  • 해결 여부

    미해결

main 함수에서 failed 가 뜨는데 어느 부분이 잘못되었는지 궁금합니다.

19.05.24 17:43 작성 조회수 166

0

다양한 방법으로 시도하는데

계속 main 함수부분만 failed가 뜨네요 왜 그럴까요?

어느부분을 잘못 접근했는지 정말 궁금합니다.

 

 

전체소스

# -*- coding: utf-8 -*-


def is_positive_number(integer_str_value):
# '''
# Input:
# - integer_str_value : 숫자형태의 문자열 값
# Output:
# - integer_str_value가 양수일 경우에는 True,
# integer로 변환이 안되거나, 0, 음수일 경우에는 flase
# Examples:
# >>> import factorial_calculator as fc
# >>> fc.is_positive_number("100")
# True
# >>> fc.is_positive_number("0")
# False
# >>> fc.is_positive_number("-10")
# False
# >>> fc.is_positive_number("abc")
# False
# '''
try:
# ===Modify codes below=============
if int(integer_str_value) > 0:
return True
else:
return False
# ==================================
except ValueError:
return False


def get_factorial_value(integer_value):
# '''
# Input:
# - integer_value : 자연수 값
# Output:
# - integer_value의 Factorial 값
# Examples:
# >>> import factorial_calculator as fc
# >>> fc.get_factorial_value(5)
# 120
# >>> fc.get_factorial_value(7)
# 5040
# '''
# ===Modify codes below=============
result = 1
for num in range(1, integer_value + 1):
result *= num

# ==================================
return result


def main():
user_input = 999
# ===Modify codes below=============
while user_input != 0:
user_input = input("Input a positive number : ")
if is_positive_number(user_input):
print(get_factorial_value(int(user_input)))
elif user_input == '0':
user_input = 0
print("Thank you for using this program")
else:
print("input again, Please")
 
# ==================================


if __name__ == "__main__":
main()

 

결과

Input a positive number : 10
3628800
Input a positive number : 3
6
Input a positive number : 5
120
Input a positive number : abc
input again, Please
Input a positive number : ls
input again, Please
Input a positive number : 32.3
input again, Please
Input a positive number : 0
Thank you for using this program

 

답변 2

·

답변을 작성해보세요.

1

저희 테스트가 그리 똑똑하지 않습니다. `Input agian` 같은 경우 대소문자 확인이 필요해 보입니다. 

0

윤지환님의 프로필

윤지환

질문자

2019.05.26

확인 감사합니다 정상적으로 처리 되네요 

열공하겠습니다.~!