Finding minimum value with python condition

a = []
for i in range(3):
    a.append(input())
j = 0
for i in a:
   if i % 10 != 7:
       j = min(a)
print j

I need an algorithm that finds the smallest positive number in a list whose decimal representation does not end with number 7. It is guaranteed that the list has at least one positive element whose decimal representation does not end with number 7. I tried this, but the condition does not work. For example: it says that 7 is the smallest in [9,8,7].

+4
source share
2 answers

a, , a. , 7 a ; , , :

a = []
for i in range(3):
    value = input()
    if i % 10 != 7 and i >= 0:
        a.append(value)

print min(a)

, :

a = []
for i in range(3):
    a.append(input())

print min(i for i in a if i % 10 != 7 and i >= 0)
+4

EDIT: , , , , , . , .

if ((i / 10) - int(i / 10)) * 10 != 7:

, Python 3, :

from __future__ import division

float float(), .

0

Source: https://habr.com/ru/post/1543669/


All Articles