我使用 Python 撰寫了這樣的代碼:
a = int(input("number = "))
def solution(a) :
b = 1
c = 0
for b in range (1,a) :
if b%3==0 or b%5==0 :
c = b
print(" ",b,end=" ")
if b>=a-1 :
print("=",c)
solution(a)
但是當我運行這段代碼時,它顯示的是:
number = 10
3 5 6 9 = 23
如何洗掉數字3之前的 ?
謝謝
uj5u.com熱心網友回復:
嘗試:
a = int(input("number = "))
def solution(a) :
b = 1
c = 0
for b in range (1,a) :
#For first iteration
if c == 0:
if b%3==0 or b%5==0 :
c = b
print(b,end=" ")
#For remaining numbers
if c>b and b%3==0 or b%5==0:
c = b
print(" ",b,end=" ")
if b>=a-1 :
print("=",c)
solution(a)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/418597.html
標籤:
上一篇:當螢屏不是全屏時,使影像不可用
