I was solving a collection of paiza level-up questions, but I didn't have a model answer, so I made it myself. The language is Python3.
Paiza's skill check sample problem Smallest value (equivalent to paiza rank D) https://paiza.jp/works/mondai/skillcheck_sample/min_num?language_uid=python3 I couldn't see the problem statement without logging in. Registration is free and can be done immediately, so I recommend you to register for the time being.
I thought it would be uninteresting to use the min function, so I dared to write it redundantly.
min_num.py
#Save the entered value
n_1 = int(input())
n_2 = int(input())
n_3 = int(input())
n_4 = int(input())
n_5 = int(input())
#Find the smallest number
ans = n_1
if n_2 < n_1:
ans = n_2
if n_3 < ans:
ans = n_3
if n_4 < ans:
ans = n_4
if n_5 < ans:
ans = n_5
#Output the answer
print(ans)
I tried to make the previous one a little easier to see by using a for statement and a list structure.
min_num.py
#Save the entered value
n = [int(input()) for i in range(5)]
#Find the smallest number
ans = n[0]
for i in range(4):
if n[i+1] < ans:
ans = n[i+1]
#Output the answer
print(ans)
I tried using the min function.
min_num.py
#Save the entered value
n = [int(input()) for i in range(5)]
#Find the smallest number
ans = min(n)
#Output the answer
print(ans)
https://qiita.com/KoyanagiHitoshi/items/3286fbc65d56dd67737c
Feel free to comment if you have any questions. I will answer as much as possible!
Recommended Posts