2024年5月9日 星期四

【ZEROJUDGE】c002. 10696 - f91

 ZEROJUDGEc002. 10696 - f91

https://zerojudge.tw/ShowProblem?problemid=c002

解題思路-Python-給我自己

函式f(n):
  如果n小於等於100,回傳f(f(n+11))
  否則回傳(n-10)

主程式

1。我用一個空的list來放結果。s=[]

2。輸入n

3。用while,n不等於0時做:
  呼到函式後的結果整理成所需的字串資料後放入s
  重新輸入n

4。用迴圈印出s

--------------------------

程式碼

def f(n):

    if n<=100:

        return(f(f(n+11)))

    else:

        return(n-10)

s=[]

n=int(input())

while n!=0:

    s.append('f91('+str(n)+') = '+ str(f(n)))

    n=int(input())

for i in s:

    print(i)

#原本我S用字串串接,最後放換行符號

#但最後多了一個\n,被判定OLE,(請勿輸出題目未要求的文字: )所以後來放LIST再輸出