練習問題/解答例/世界のナベアツ問題/Python

Python

#!/usr/bin/env python
def nabeatsu(n):
    return ['Aho' if i%3==0 or '3' in str(i) else i for i in range(1,n+1)]

print(nabeatsu(input('n:')))

#わかりやすく

n = 1
while n + 1> n:
	 if n % 3 == 0:
		 print "aho"
	 elif "3" in str(n): 
		 print "aho"
	 else:
		 print n
	 n += 1

↑の無限ループを排除

n = int(raw_input('n: '))
for i in xrange(1, n+1):
    if i % 3 == 0:
        print "aho"
    elif "3" in str(i): 
        print "aho"
    else:
        print i