# Level5 Python List3 homework
###### tags: `Python`
## Q1
:::success
```python=
import random
# モンスターの名前リスト
monster_name=["アリス","サタナエル","スカアハ"]
# モンスターのHPリスト
monster_hp=[350,500,400]
# スキルリスト
skill_list = ["死んでくれる", "逃げる"]
# 命中リスト
acu_list = [70, 50]
# スキルの最小ダメージと最大ダメージ
dam_min = 120
dam_max = 180
# エンカウントモンスターの決定
rand_num = random.randrange(len(monster_name))
enemy_name = monster_name[rand_num]
enemy_hp = monster_hp[rand_num]
# エンカウント
print("野生の{}が現れました".format(enemy_name))
# 戦闘
while enemy_hp > 0:
# コマンド選択
print("どうしますか?")
command_num = int(input("0.死んでくれる? 1.逃げる: "))
# 死んでくれる? 選択
if command_num == 0:
if 0 <= random.randrange(100) < acu_list[0]:
atk = random.randint(dam_min, dam_max)
print("{}に{}点ダメージを与えました。".format(enemy_name, atk))
enemy_hp -= atk
print("残りHP:{}".format(enemy_hp))
else:
print("うまく当たらなかった!!")
# 逃げる 選択
elif command_num == 1:
if 0 <= random.randrange(100) < acu_list[1]:
print("逃げた!")
break
else:
print("逃げられなかった!")
else:
print("勝ちました")
```
:::
## Q2
:::success
```python=
# 名前リスト
name_list = list()
# 値段リスト
price_list = list()
# 商品の登録
print("Create Price Table")
# 商品の個数
amount = int(input("How much goods:"))
for i in range(amount):
name_list.append(input("Register goods name{}:".format(i+1)))
price_list.append(int(input("Register the price{}:".format(i+1))))
# 商品登録完了
print("Completion of registration")
# 商品の情報出力
print("Goods: {}".format(name_list))
print("Price: {}".format(price_list))
# 総額計算用
total = 0
# 購入ナンバーに「-1」が入力されるまで続ける
while True:
# 購入する商品ナンバー、個数入力
sel_num = int(input("0~{}から購入するものを入力:".format(len(name_list)-1)))
# 「-1」で購入終了
if sel_num == -1:
break
value = int(input("何個?"))
# カートに入れる
total += price_list[sel_num] * value
print("{}を{}個カートに入れました。".format(name_list[sel_num], value))
# 購入完了
print("Thank you for your purchase")
print("Total:{}".format(total))
```
:::
## Q3
:::success
```python=
import random
# 賞品一覧
award_list = ['Ps5', '商品券300円', '商品券100円']
print("Before:", award_list)
# 確率リスト
possible_list = [3, 80, 100]
# シャッフル済賞品リスト
shuf_list = list()
# シャッフル済確率リスト
shuf_poss_list = list()
# 重複確認用リスト
conf_list = award_list.copy()
# 違う並びになるまでLOOPを繰り返す
while True:
for i in range(len(award_list)):
rand_num = random.randrange(len(award_list))
shuf_list.append(award_list.pop(rand_num))
shuf_poss_list.append(possible_list.pop(rand_num))
# 違う並びになったらbreak
if conf_list != shuf_poss_list:
break
print("After:", shuf_list)
# 選択済みリスト作成
selected_list = [False] * 3
# 抽選箱の表示
print("-------------")
print("| 1 | 2 | 3 |")
print("-------------")
# 抽選番号入力
select = int(input("抽選:"))
# 該当する場所を選択済みにし、獲得賞品の出力
selected_list[select-1] = True
# 確率の生成、当たったかどうか
if 0 <= random.randrange(100) < shuf_poss_list[select-1]:
print("おめでとう、{}を獲得しました".format(shuf_list[select-1]))
else:
print("またの機会を心よりお待ちしています")
# 抽選箱の画像作成
string = "|"
for i in range(len(shuf_list)):
string += " "
# 選択済みであれば「x」を、そうでなれば数字をそのまま追加する
string += str(i+1) if not selected_list[i] else "x"
string += " |"
# 抽選箱の表示
print("-" * 13)
print(string)
print("-------------")
```
:::