LoginSignup
0
0

【Paiza問題集】ループメニュー1/数列同士の引き算

Posted at

Paiza問題集

Pythonで回答

ループメニュー1/数列同士の引き算

Step01 数列の和

"""
数列の和
https://paiza.jp/works/mondai/loop_problems/loop_problems__seq_sum

問題
数列の和を計算し、出力してください
出力の末尾には改行を入れてください
"""

N = int(input())
A = map(int, (input().split()))

sum = 0
for i in A:
    sum += i

print(sum)

Step02 数列のA番目からB番目までの和

"""
数列のA番目からB番目までの和
https://paiza.jp/works/mondai/loop_problems/loop_problems__seq_partsum

問題
数列のA番目からB番目までの和を計算し、出力してください
出力の末尾には改行を入れてください
"""

N, A, B = map(int, (input().split()))
a = list(map(int, (input().split())))

sum = 0
for i in range(A-1, B, +1):
    sum += a[i]

print(sum)

Step03 数列の値を全部*2して出力

"""
数列の値を全部*2して出力
https://paiza.jp/works/mondai/loop_problems/loop_problems__seq_multi

問題
数列の全ての要素を2倍し、改行区切りで出力してください
出力の末尾には改行を入れてください
"""

N = int(input())
a = list(map(int, (input().split())))

[print(a[i]*2) for i in range(N)]

Final問題 数列同士の引き算

"""
数列同士の引き算
https://paiza.jp/works/mondai/loop_problems/loop_problems__seq_sub

問題
1行目に整数Nが与えられます
2行目に長さNの数列aが与えられます
3行目に長さNの数列bが与えられます
aの各要素からbの各要素を引いた結果を、改行区切りで出力してください
出力の末尾には改行を入れてください
"""

N = int(input())
a = list(map(int, (input().split())))
b = list(map(int, (input().split())))

[print(a[i]-b[i]) for i in range(N)]
0
0
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
0
0