2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Python 年末年始の宿題

Posted at

◆問題1(復習)
 引数なし、返値なし
 関数ないで、'Hello, World'と表示

'Hello, World'

◆問題2(復習)
 引数1までの、
 1~引数1までの和を返す関数

def wa (z):
a,b = 0,0
while a < z:
a = a + 1
b = a + b
print (b)

In :wa(3)
Out:10

◆問題3
 引数1、引数2を渡して、
 引数1~引数2までの整数のリストを返す関数

def func(a,b):
show = list(range(a,b))
print(show)

In :func(3,6)
Out:[3,4,5]

◆問題4
 引数1までのフィボナッチ数のリストを返す関数
 0,1,1,2,3,5,8
 隣どうしの数を足した数が次の要素になる数列

def fib(n):
a,b = 0,1
while a < n:
print(a, end = ' ')
a,b = b,a+b

In :fib(2000)
Out:0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597

◆問題5
 FizzBuzz関数
 3の倍数の時'Fizz'と表示
 5の倍数の時'Buzz'と表示
 3の倍数かつ5の倍数の時'FizzBuzz'と表示
 上記以外の場合は、そのまま数字を表示
 引数1まで繰り返す

def FizzBuzz(n):
game = ['FizzBuzz' if x % 15 == 0
else 'Fizz' if x % 3 == 0
else 'Buzz' if x % 5 == 0
else x for x in range(1,n)]
print(game)

In :FizzBuzz(20)
Out:省略

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?