Solve the smallest value in Python (equivalent to paiza rank D)

at first

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.

problem

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.

Answer code

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)

Answer code 2

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)

Answer code 3

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)

reference

https://qiita.com/KoyanagiHitoshi/items/3286fbc65d56dd67737c

Finally

Feel free to comment if you have any questions. I will answer as much as possible!

Recommended Posts

Solve the smallest value in Python (equivalent to paiza rank D)
Solve addition (equivalent to paiza rank D) in Python
Solve multiplication (equivalent to paiza rank D) in Python
Solve number sorting (equivalent to paiza rank D) in Python
Solve character matches (equivalent to paiza rank D) in Python
Solve island hunting (equivalent to paiza rank S) in Python
Solve word counts (equivalent to paiza rank C) in Python
Solve mod7 fortune-telling (equivalent to paiza rank S) in Python
Solve Fizz Buzz (equivalent to paiza rank C) in Python
How to retrieve the nth largest value in Python
Solve ABC175 D in Python
To do the equivalent of Ruby's ObjectSpace._id2ref in Python
How to get the last (last) value in a list in Python
[Python] Find the second smallest value.
The 17th Offline Real-time How to Solve Writing Problems in Python
I wanted to solve the ABC164 A ~ D problem with Python
What to do when the value type is ambiguous in Python?
I wanted to solve ABC159 in Python
Solve ABC165 A, B, D in Python
Solve the maximum subarray problem in Python
[At Coder] What I did to reach the green rank in Python
How to use the C library in Python
Try to solve the Python class inheritance problem
Try to solve the man-machine chart with Python
To dynamically replace the next method in python
Draw graphs in Julia ... Leave the graphs to Python
Find the divisor of the value entered in python
[Mac] Run the RealSense D415 sample in Python
The trick to write flatten concisely in python
How to get the files in the [Python] folder
I want to display the progress in Python!
I tried to graph the packages installed in Python
How to get the variable name itself in python
Try to solve the programming challenge book with python3
Solve ABC168D in Python
Solve ABC167-D in Python
How to get the number of digits in Python
Solve ABC146-C in Python
How to know the current directory in Python in Blender
Try to solve the internship assignment problem with Python
How to identify the element with the smallest number of characters in a Python list?
I tried to solve the soma cube with python
Convert the image in .zip to PDF with Python
Solve ABC098-C in Python
Solve ABC159-D in Python
Get the value selected in Selenium Python VBA pull-down
I want to write in Python! (3) Utilize the mock
Solve ABC169 in Python
How to use the model learned in Lobe in Python
I tried to solve the problem with Python Vol.1
Solve the one-stroke writing (backtrack without recursion in Python)
[Python] How to output the list values in order
I want to use the R dataset in python
Solve ABC160-E in Python
Python OpenCV tried to display the image in text.
[C / C ++] Pass the value calculated in C / C ++ to a python function to execute the process, and use that value in C / C ++.
How to check if the contents of the dictionary are the same in Python by hash value
I tried to create a Python script to get the value of a cell in Microsoft Excel
I want to initialize if the value is empty (python)
[python] How to check if the Key exists in the dictionary
I wanted to solve the Panasonic Programming Contest 2020 with Python