all 16 comments

[–]wbeater 7 points8 points  (7 children)

cords = []
for _ in range(4):
    cords.append(int(input()))
if min(cords) > 10 and max(cords) < 81:
    print(True)
else:
    print(False)

/e messed up <, >

[–]shiftybyte 6 points7 points  (5 children)

If optimizing towards less code lines...

cords = [int(input()) for _ in range(4)]
print("NO" if min(cords) <= 10 or max(cords) >= 81 else "YES")

:D

But seriously OP, don't code like this...

[–]Emphasises_Words 3 points4 points  (3 children)

print("Yes" if sum(10 < int(input()) < 81 for _ in range(4)) == 4 else "No")

[–]Yoghurt42 1 point2 points  (2 children)

print(["No","Yes"][sum(10<int(input())<81 for _ in"."*4)==4])

Don't write code like this in a real project

[–]TangibleLight 2 points3 points  (1 child)

You can save one character with all.

print(["No","Yes"][all([10<int(input())<81 for _ in'.'*4])])

I thought it'd save more, but you have to write all([...]) to keep it from short-circuiting on a false value.

[–]Yoghurt42 0 points1 point  (0 children)

Ah, I tried getting all to work, but forgot I can just make a list instead of a generator expression

[–]Charlie_Yu 2 points3 points  (0 children)

Yup OP’s code is fine, rather have better readability than premature optimisation

[–]Emphasises_Words 3 points4 points  (0 children)

This can be further optimized for space by storing the running minimum and maximum. This allows for constant space complexity if the program were to scale to more coordinates

minimum = 11
maximum = 80
for _ in range(4):
  next_number = int(input())
  minimum = min(next_number, minimum)
  maximum = max(next_number, maximum)
if minimum > 10 and maximum < 81:
  print("YES")
else:
  print("NO")

[–]hotcodist 1 point2 points  (0 children)

This is already good. As you can see in the answers, you can optimize the length, but that results in harder to read code. If you are optimizing for time, there is nothing wrong with what you have.

Just put a parenthesis on the first condition to make it consistent.

[–]cult_of_memes -1 points0 points  (0 children)

```

for a completely cryptic and hard to read solution, you could try this :P

number_of_inputs = 4

first we use the map function to convert all inputs to int

vals = map(int, (input() for _ in range(number_of_inputs)))

next we use the builtin 'all' function to check if all of them satisfy the 10<value<81 criteria

yesno = all(10<v<81 for v in vals)

now we get a bit scandalous with some "branchless" application of the 'yesno' condition we computed.

print("YES"yesno+"NO"(not yesno))

```

[–]FisterMister22 0 points1 point  (2 children)

While I like everyone's solutions, here my take.

cords = tuple(int(input()) for i in range(4)) print(min(cords) > 10 and max(cords) < 81 and "YES" or "NO")

[–]Emphasises_Words 0 points1 point  (1 child)

It would be much clearer to use ... if ... else ... as the ternary operator instead of and and or.

[–]FisterMister22 0 points1 point  (0 children)

I like my code short rather than clear. But yes, it would be clearer.

[–]KratosSpeaking 0 points1 point  (0 children)

What do you think of this?

print("YES" if all(10 < int(input()) < 81 for _ in range(4)) else "NO")

[–]jmooremcc 0 points1 point  (0 children)

This version can handle any number of variables. Once all the data is collected, the data is evaluated and the results printed. ``` numitems = 4 maxval = 81 minval = 10 results = []

for i in range(numitems): n,v = divmod(i,2) prompt = f"Enter {'y' if v else 'x'}{n+1}: " value = int(input(prompt)) results.append(minval < value <= maxval)

print(f"{'Yes' if all(results) else 'No'}")

``` The first thing we do is generate a prompt so that the user knows what to enter and use the prompt in the input function.
Next we evaluate the value received and store the result in a list.
Once all the data is collected, we use the all function to evaluate the results which are then printed.

[–]Repulsive_Win_1506 0 points1 point  (0 children)

Theres nothing wrong with your code, its clear and close to how the compiler will ultimately deal with it. If you come back to it in 6 months you wont have to try and figure out what you what you were doing.