How to exclude a number from 3 numbers that is not min and max, elegant solution[python]?
There are 3 numbers given, need to print min, then max, then the number in between.
I dont want to write it using ifs, I m seeking more elegant solution to find a number that's not min and max out of 3.
a = int(input())
b = int(input())
c = int(input())
m = max(a,b,c)
minim = min(a,b,c)
print(m)
print(minim)
l = new list(a,b,c)
#how to exclude a 3rd element from a list that's not min and max?
number = list - m - minim
print(number)
python
|
show 1 more comment
There are 3 numbers given, need to print min, then max, then the number in between.
I dont want to write it using ifs, I m seeking more elegant solution to find a number that's not min and max out of 3.
a = int(input())
b = int(input())
c = int(input())
m = max(a,b,c)
minim = min(a,b,c)
print(m)
print(minim)
l = new list(a,b,c)
#how to exclude a 3rd element from a list that's not min and max?
number = list - m - minim
print(number)
python
1
I have no idea what you're asking.
– roganjosh
Nov 19 '18 at 15:35
new_list = [m, minim]
– floydya
Nov 19 '18 at 15:37
@roganjosh i have updated it sir, pls kindly look and help me
– ERJAN
Nov 19 '18 at 15:38
5
sorted([a,b,c])[1]
?
– Chris_Rands
Nov 19 '18 at 15:39
2
It still doesn't make sense. What you've posted is not valid python. For 10k rep, I would have expected you can do equality checks. Why do you need to exclude the "middle" value here, since you never reference it anyway?
– roganjosh
Nov 19 '18 at 15:40
|
show 1 more comment
There are 3 numbers given, need to print min, then max, then the number in between.
I dont want to write it using ifs, I m seeking more elegant solution to find a number that's not min and max out of 3.
a = int(input())
b = int(input())
c = int(input())
m = max(a,b,c)
minim = min(a,b,c)
print(m)
print(minim)
l = new list(a,b,c)
#how to exclude a 3rd element from a list that's not min and max?
number = list - m - minim
print(number)
python
There are 3 numbers given, need to print min, then max, then the number in between.
I dont want to write it using ifs, I m seeking more elegant solution to find a number that's not min and max out of 3.
a = int(input())
b = int(input())
c = int(input())
m = max(a,b,c)
minim = min(a,b,c)
print(m)
print(minim)
l = new list(a,b,c)
#how to exclude a 3rd element from a list that's not min and max?
number = list - m - minim
print(number)
python
python
edited Nov 19 '18 at 15:37
asked Nov 19 '18 at 15:34


ERJAN
9,205113466
9,205113466
1
I have no idea what you're asking.
– roganjosh
Nov 19 '18 at 15:35
new_list = [m, minim]
– floydya
Nov 19 '18 at 15:37
@roganjosh i have updated it sir, pls kindly look and help me
– ERJAN
Nov 19 '18 at 15:38
5
sorted([a,b,c])[1]
?
– Chris_Rands
Nov 19 '18 at 15:39
2
It still doesn't make sense. What you've posted is not valid python. For 10k rep, I would have expected you can do equality checks. Why do you need to exclude the "middle" value here, since you never reference it anyway?
– roganjosh
Nov 19 '18 at 15:40
|
show 1 more comment
1
I have no idea what you're asking.
– roganjosh
Nov 19 '18 at 15:35
new_list = [m, minim]
– floydya
Nov 19 '18 at 15:37
@roganjosh i have updated it sir, pls kindly look and help me
– ERJAN
Nov 19 '18 at 15:38
5
sorted([a,b,c])[1]
?
– Chris_Rands
Nov 19 '18 at 15:39
2
It still doesn't make sense. What you've posted is not valid python. For 10k rep, I would have expected you can do equality checks. Why do you need to exclude the "middle" value here, since you never reference it anyway?
– roganjosh
Nov 19 '18 at 15:40
1
1
I have no idea what you're asking.
– roganjosh
Nov 19 '18 at 15:35
I have no idea what you're asking.
– roganjosh
Nov 19 '18 at 15:35
new_list = [m, minim]
– floydya
Nov 19 '18 at 15:37
new_list = [m, minim]
– floydya
Nov 19 '18 at 15:37
@roganjosh i have updated it sir, pls kindly look and help me
– ERJAN
Nov 19 '18 at 15:38
@roganjosh i have updated it sir, pls kindly look and help me
– ERJAN
Nov 19 '18 at 15:38
5
5
sorted([a,b,c])[1]
?– Chris_Rands
Nov 19 '18 at 15:39
sorted([a,b,c])[1]
?– Chris_Rands
Nov 19 '18 at 15:39
2
2
It still doesn't make sense. What you've posted is not valid python. For 10k rep, I would have expected you can do equality checks. Why do you need to exclude the "middle" value here, since you never reference it anyway?
– roganjosh
Nov 19 '18 at 15:40
It still doesn't make sense. What you've posted is not valid python. For 10k rep, I would have expected you can do equality checks. Why do you need to exclude the "middle" value here, since you never reference it anyway?
– roganjosh
Nov 19 '18 at 15:40
|
show 1 more comment
2 Answers
2
active
oldest
votes
You can simply sort the list - minimum and maximum will be at the ends, and the middle number in the middle. Use index access () to fetch individual elements:
numbers = sorted((a, b, c))
print('minimum:', numbers[0])
print('maximum:', numbers[2])
print('middle :', numbers[1])
add a comment |
a = int(input())
b = int(input())
c = int(input())
m = max(a,b,c)
minim = min(a,b,c)
print(m)
print(minim)
l = [a,b,c]
#sum - max - min
number = sum(l) - m - minim
print(number)
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53377945%2fhow-to-exclude-a-number-from-3-numbers-that-is-not-min-and-max-elegant-solution%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can simply sort the list - minimum and maximum will be at the ends, and the middle number in the middle. Use index access () to fetch individual elements:
numbers = sorted((a, b, c))
print('minimum:', numbers[0])
print('maximum:', numbers[2])
print('middle :', numbers[1])
add a comment |
You can simply sort the list - minimum and maximum will be at the ends, and the middle number in the middle. Use index access () to fetch individual elements:
numbers = sorted((a, b, c))
print('minimum:', numbers[0])
print('maximum:', numbers[2])
print('middle :', numbers[1])
add a comment |
You can simply sort the list - minimum and maximum will be at the ends, and the middle number in the middle. Use index access () to fetch individual elements:
numbers = sorted((a, b, c))
print('minimum:', numbers[0])
print('maximum:', numbers[2])
print('middle :', numbers[1])
You can simply sort the list - minimum and maximum will be at the ends, and the middle number in the middle. Use index access () to fetch individual elements:
numbers = sorted((a, b, c))
print('minimum:', numbers[0])
print('maximum:', numbers[2])
print('middle :', numbers[1])
answered Nov 19 '18 at 15:41
MisterMiyagi
7,4042142
7,4042142
add a comment |
add a comment |
a = int(input())
b = int(input())
c = int(input())
m = max(a,b,c)
minim = min(a,b,c)
print(m)
print(minim)
l = [a,b,c]
#sum - max - min
number = sum(l) - m - minim
print(number)
add a comment |
a = int(input())
b = int(input())
c = int(input())
m = max(a,b,c)
minim = min(a,b,c)
print(m)
print(minim)
l = [a,b,c]
#sum - max - min
number = sum(l) - m - minim
print(number)
add a comment |
a = int(input())
b = int(input())
c = int(input())
m = max(a,b,c)
minim = min(a,b,c)
print(m)
print(minim)
l = [a,b,c]
#sum - max - min
number = sum(l) - m - minim
print(number)
a = int(input())
b = int(input())
c = int(input())
m = max(a,b,c)
minim = min(a,b,c)
print(m)
print(minim)
l = [a,b,c]
#sum - max - min
number = sum(l) - m - minim
print(number)
answered Nov 19 '18 at 15:39
Rudolf Morkovskyi
720117
720117
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53377945%2fhow-to-exclude-a-number-from-3-numbers-that-is-not-min-and-max-elegant-solution%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
I have no idea what you're asking.
– roganjosh
Nov 19 '18 at 15:35
new_list = [m, minim]
– floydya
Nov 19 '18 at 15:37
@roganjosh i have updated it sir, pls kindly look and help me
– ERJAN
Nov 19 '18 at 15:38
5
sorted([a,b,c])[1]
?– Chris_Rands
Nov 19 '18 at 15:39
2
It still doesn't make sense. What you've posted is not valid python. For 10k rep, I would have expected you can do equality checks. Why do you need to exclude the "middle" value here, since you never reference it anyway?
– roganjosh
Nov 19 '18 at 15:40