10月22日(リスト)

ページ名:10月22日

リストとは

データを順番に並べて管理したもの

member = ['阿部', '伊藤', '上村', '遠藤', '岡村']
member[1]
 
*問題1
①明治から令和までの元号をリストで表示しなさい。
②このリストを使って「平成の次の元号は令和です」と表示しなさい。
*
gengou = ['明治','大正','昭和','平成','令和']
print(gengou[3] + 'の次の元号は' + gengou[4] + 'です')
 
問題2
①ラグビーの世界ランキング1位~3位を調べてリストで表しなさい。
②「ラグビー世界ランキング1位は○○、2位は○○、3位は○○です」と表示するプログラムを作りなさい。
 
rugby = ['イングランド','南アフリカ','ニュージーランド']
print('ラグビー世界ランキング1位は' + rugby[0] + '2位は' + rugby[1] + '3位は' + rugby[2] + 'です')

グラフを描く

%matplotlib inline
import matplotlib.pyplot as plt
yen = [111.7, 110.2, 108.1, 108.2, 106.3]
plt.plot(yen)
 
問題1: 朝来市の気温の変化を調べたいと思います
①朝来市の10/2428の最高気温を調べて、リストで表しなさい
5日間の気温のグラフを描きなさい
10/27の気温を表示しなさい
10/2810/24の気温の差を求めなさい
5日間の平均気温を求めなさい

%matplotlib inline
import matplotlib.pyplot as plt
kion = [18.3, 16.8, 22.4, 20.9, 21.2]
plt.plot(kion)
print(kion[3])
print(kion[4] - kion[0])
print((kion[0] + kion[1] + kion[2] + kion[3] + kion[4])/5)

グラフを重ねて描く

%matplotlib inline
import matplotlib.pyplot as plt
ikuno = [18.3, 16.8, 22.4, 20.9, 21.2]
wadayama = [18.6, 17.5, 22.3, 21.0, 21.4]
plt.plot(ikuno)
plt.plot(wadayama)
 
*問題:朝来市と豊岡市の人口の変化を調べたいと思います
 ①両市のそれぞれの過去5年間の人口を調べなさい
 ②朝来市と豊岡市の人口のグラフを重ねて描きなさい
 ③朝来市と豊岡市では人口の減少率はどちらが大きいですか?それが分かるグラフを描きなさい。

 

%matplotlib inline
import matplotlib.pyplot as plt
asago = [32462, 32065, 31679, 31248, 30845]
toyooka = [82462, 82250, 81391, 80595, 79428]
plt.plot(asago)
plt.plot(toyooka)

%matplotlib inline
import matplotlib.pyplot as plt
asago = [32462/32462, 32065/32462, 31679/32462, 31248/32462, 30845/32462]
toyooka = [82462/82462, 82250/82462, 81391/82462, 80595/82462, 79428/82462]
plt.plot(asago)
plt.plot(toyooka)

リストの操作

member = ['阿部', '伊藤', '上村', '遠藤', '岡村']
member[1] = '伊東' #置き換え
print(member)
member.remove('伊東') #削除
print(member)
member.append('加藤') #追加
print(member)
del member[3] #削除
print(member)
member2 = ['Allen', 'Bob', 'Catherine']
print(member + member2) #連結
print(member[1:3]) #一部を取り出す
print(member[1:]) #一部を取り出す
print(member[:3]) #一部を取り出す
 

リストと入出力

gohan = [] #空のリストを作る
gohan.append(input('朝ご飯は?'))
gohan.append(input('昼ご飯は?'))
gohan.append(input('夜ご飯は?'))
print('今日のご飯は' + gohan[0] + '' +
gohan[1] + '' + gohan[2] + 'です')
 
*問題: 3つの数の入力を受けて、その平均を出力するプログラムを書きなさい
*
問題:1学期, 2学期, 3学期の英語と数学の点数をそれぞれ入力すると、それぞれのグラフを表示するプログラムを書きなさい

(信木さんへ:ランダムの作り方)

list = [x for x in range(100)] #[1, 2, 3, ...., 100]
mondailist = []
while len(list) > 0:
    mondailist.append(list1.pop(random.randrange(len(list))))

...

ima = 0
nanmon = 0

...

def nextquiz:
    nanmon += 1
    ima = mondailist[nanmon]

 

シェアボタン: このページをSNSに投稿するのに便利です。

コメント

返信元返信をやめる

※ 悪質なユーザーの書き込みは制限します。

最新を表示する

NG表示方式

NGID一覧