If statement only printing else
def quantity():
global amount
amount = input('How many tickets are you looking for? ')
if amount == range(1,7):
print('You have selected tickets '.format(amount))
elif amount == (0):
print('You have selected 0 tickets')
else:
print('Please choose an amount between 0-6')
I'm trying to create ticket cost calculator to jog my memory but I was stumped on the IF statement for the quantity section because it only prints the ELSE even when IF and ELIF are true.
python
add a comment |
def quantity():
global amount
amount = input('How many tickets are you looking for? ')
if amount == range(1,7):
print('You have selected tickets '.format(amount))
elif amount == (0):
print('You have selected 0 tickets')
else:
print('Please choose an amount between 0-6')
I'm trying to create ticket cost calculator to jog my memory but I was stumped on the IF statement for the quantity section because it only prints the ELSE even when IF and ELIF are true.
python
1
Possible duplicate of How can I read inputs as integers?
– tripleee
Nov 15 '18 at 4:59
1
@tripleee: The dupe you're suggesting doesn't cover the comparison to arange
value, but you're about halfway there.
– Makoto
Nov 15 '18 at 5:00
@Makoto but that wasn't the main concern of OP, the question was why do both IF and ELIF fail, and the reason is covered in the duplicate. i.e. without conversion ELIF alway fails, with conversion it is true for 0.
– Emil Vatai
Nov 15 '18 at 5:10
add a comment |
def quantity():
global amount
amount = input('How many tickets are you looking for? ')
if amount == range(1,7):
print('You have selected tickets '.format(amount))
elif amount == (0):
print('You have selected 0 tickets')
else:
print('Please choose an amount between 0-6')
I'm trying to create ticket cost calculator to jog my memory but I was stumped on the IF statement for the quantity section because it only prints the ELSE even when IF and ELIF are true.
python
def quantity():
global amount
amount = input('How many tickets are you looking for? ')
if amount == range(1,7):
print('You have selected tickets '.format(amount))
elif amount == (0):
print('You have selected 0 tickets')
else:
print('Please choose an amount between 0-6')
I'm trying to create ticket cost calculator to jog my memory but I was stumped on the IF statement for the quantity section because it only prints the ELSE even when IF and ELIF are true.
python
python
asked Nov 15 '18 at 4:55
WalkingLickWalkingLick
31
31
1
Possible duplicate of How can I read inputs as integers?
– tripleee
Nov 15 '18 at 4:59
1
@tripleee: The dupe you're suggesting doesn't cover the comparison to arange
value, but you're about halfway there.
– Makoto
Nov 15 '18 at 5:00
@Makoto but that wasn't the main concern of OP, the question was why do both IF and ELIF fail, and the reason is covered in the duplicate. i.e. without conversion ELIF alway fails, with conversion it is true for 0.
– Emil Vatai
Nov 15 '18 at 5:10
add a comment |
1
Possible duplicate of How can I read inputs as integers?
– tripleee
Nov 15 '18 at 4:59
1
@tripleee: The dupe you're suggesting doesn't cover the comparison to arange
value, but you're about halfway there.
– Makoto
Nov 15 '18 at 5:00
@Makoto but that wasn't the main concern of OP, the question was why do both IF and ELIF fail, and the reason is covered in the duplicate. i.e. without conversion ELIF alway fails, with conversion it is true for 0.
– Emil Vatai
Nov 15 '18 at 5:10
1
1
Possible duplicate of How can I read inputs as integers?
– tripleee
Nov 15 '18 at 4:59
Possible duplicate of How can I read inputs as integers?
– tripleee
Nov 15 '18 at 4:59
1
1
@tripleee: The dupe you're suggesting doesn't cover the comparison to a
range
value, but you're about halfway there.– Makoto
Nov 15 '18 at 5:00
@tripleee: The dupe you're suggesting doesn't cover the comparison to a
range
value, but you're about halfway there.– Makoto
Nov 15 '18 at 5:00
@Makoto but that wasn't the main concern of OP, the question was why do both IF and ELIF fail, and the reason is covered in the duplicate. i.e. without conversion ELIF alway fails, with conversion it is true for 0.
– Emil Vatai
Nov 15 '18 at 5:10
@Makoto but that wasn't the main concern of OP, the question was why do both IF and ELIF fail, and the reason is covered in the duplicate. i.e. without conversion ELIF alway fails, with conversion it is true for 0.
– Emil Vatai
Nov 15 '18 at 5:10
add a comment |
7 Answers
7
active
oldest
votes
1.The range function in python3 returns an iteration type.
2.The input function in python3 returns a string and should be converted to an integer.
Try this:
amount = int(input('How many tickets are you looking for? '))
if amount in range(1,7):
print('You have selected tickets '.format(amount))
elif amount == (0):
print('You have selected 0 tickets')
else:
print('Please choose an amount between 0-6')
Thank you, this has solved the issue for me.
– WalkingLick
Nov 15 '18 at 5:12
add a comment |
You want
if amount in range(1,7):
rather than what you currently have,
if amount == range(1,7):
It's a bit more complicated in reality (because it returns a generator rather than a list), but you can conceptualize range(1,7)
as a function that returns a list of numbers in that range. e.g.
range(1,7) ~~ [1, 2, 3, 4, 5, 6]
If your amount is an integer, you want to see if it's in that range, not if it is that range - after all, an integer cannot be a list at the same time.
[edit]: As one of the other answers pointed out, you might also want to cast the result of your input()
to an int - as input()
generally returns a string.
1
amount
isn't anint
, though. You're close.
– Makoto
Nov 15 '18 at 5:00
def quantity(): global amount amount = input('How many tickets are you looking for? ') if amount in range(1,7): print('You have selected tickets '.format(amount)) elif amount == (0): print('You have selected 0 tickets') else: print('Please choose an amount between 0-6') amount = int(amount)
So I added the if ... in and turned amount into an integer but still receive only the else part.
– WalkingLick
Nov 15 '18 at 5:09
You need to putamount = int(amount)
before you do theif
condition, not after. You could even wrap theinput()
statement in anint()
call
– Green Cloak Guy
Nov 15 '18 at 5:15
I understand now, thank you for the help.
– WalkingLick
Nov 15 '18 at 5:18
add a comment |
Try this code use in for ==
def quantity():
global amount
amount = input('How many tickets are you looking for? ')
if amount in range(1,7):
print('You have selected tickets '.format(amount))
elif amount == (0):
print('You have selected 0 tickets')
else:
print('Please choose an amount between 0-6')
add a comment |
You have to convert the input()
from a string into an integer, otherwise you will always run the else statement. You can do that with int()
, but will likely have to do some error handling in case the user enters something that cannot be converted to an integer.
add a comment |
I have made some changes to your code. I believe this is what you are looking for.
def quantity():
global amount
amount = int(input('How many tickets are you looking for? '))
if amount in range(1,7):
print('You have selected tickets '.format(amount))
elif amount ==0 :
print('You have selected 0 tickets')
else:
print('Please choose an amount between 0-6')
add a comment |
Instead of using if amount == range(1,7):
use if amount in range(1,7):
This is the modified code that you should use:
def quantity():
global amount
amount = input('How many tickets are you looking for? ')
if amount in range(1,7):
print('You have selected tickets '.format(amount))
elif amount == (0):
print('You have selected 0 tickets')
else:
print('Please choose an amount between 0-6')
add a comment |
input
returns a string, so I guess you should be doing amount = int(input('...'))
.
Am I missing something? Ahh... thein
not==
is also important... but I don't think that was the main concern of OP.
– Emil Vatai
Nov 15 '18 at 5:04
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%2f53312657%2fif-statement-only-printing-else%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
7 Answers
7
active
oldest
votes
7 Answers
7
active
oldest
votes
active
oldest
votes
active
oldest
votes
1.The range function in python3 returns an iteration type.
2.The input function in python3 returns a string and should be converted to an integer.
Try this:
amount = int(input('How many tickets are you looking for? '))
if amount in range(1,7):
print('You have selected tickets '.format(amount))
elif amount == (0):
print('You have selected 0 tickets')
else:
print('Please choose an amount between 0-6')
Thank you, this has solved the issue for me.
– WalkingLick
Nov 15 '18 at 5:12
add a comment |
1.The range function in python3 returns an iteration type.
2.The input function in python3 returns a string and should be converted to an integer.
Try this:
amount = int(input('How many tickets are you looking for? '))
if amount in range(1,7):
print('You have selected tickets '.format(amount))
elif amount == (0):
print('You have selected 0 tickets')
else:
print('Please choose an amount between 0-6')
Thank you, this has solved the issue for me.
– WalkingLick
Nov 15 '18 at 5:12
add a comment |
1.The range function in python3 returns an iteration type.
2.The input function in python3 returns a string and should be converted to an integer.
Try this:
amount = int(input('How many tickets are you looking for? '))
if amount in range(1,7):
print('You have selected tickets '.format(amount))
elif amount == (0):
print('You have selected 0 tickets')
else:
print('Please choose an amount between 0-6')
1.The range function in python3 returns an iteration type.
2.The input function in python3 returns a string and should be converted to an integer.
Try this:
amount = int(input('How many tickets are you looking for? '))
if amount in range(1,7):
print('You have selected tickets '.format(amount))
elif amount == (0):
print('You have selected 0 tickets')
else:
print('Please choose an amount between 0-6')
answered Nov 15 '18 at 5:07
myhaspldeepmyhaspldeep
16017
16017
Thank you, this has solved the issue for me.
– WalkingLick
Nov 15 '18 at 5:12
add a comment |
Thank you, this has solved the issue for me.
– WalkingLick
Nov 15 '18 at 5:12
Thank you, this has solved the issue for me.
– WalkingLick
Nov 15 '18 at 5:12
Thank you, this has solved the issue for me.
– WalkingLick
Nov 15 '18 at 5:12
add a comment |
You want
if amount in range(1,7):
rather than what you currently have,
if amount == range(1,7):
It's a bit more complicated in reality (because it returns a generator rather than a list), but you can conceptualize range(1,7)
as a function that returns a list of numbers in that range. e.g.
range(1,7) ~~ [1, 2, 3, 4, 5, 6]
If your amount is an integer, you want to see if it's in that range, not if it is that range - after all, an integer cannot be a list at the same time.
[edit]: As one of the other answers pointed out, you might also want to cast the result of your input()
to an int - as input()
generally returns a string.
1
amount
isn't anint
, though. You're close.
– Makoto
Nov 15 '18 at 5:00
def quantity(): global amount amount = input('How many tickets are you looking for? ') if amount in range(1,7): print('You have selected tickets '.format(amount)) elif amount == (0): print('You have selected 0 tickets') else: print('Please choose an amount between 0-6') amount = int(amount)
So I added the if ... in and turned amount into an integer but still receive only the else part.
– WalkingLick
Nov 15 '18 at 5:09
You need to putamount = int(amount)
before you do theif
condition, not after. You could even wrap theinput()
statement in anint()
call
– Green Cloak Guy
Nov 15 '18 at 5:15
I understand now, thank you for the help.
– WalkingLick
Nov 15 '18 at 5:18
add a comment |
You want
if amount in range(1,7):
rather than what you currently have,
if amount == range(1,7):
It's a bit more complicated in reality (because it returns a generator rather than a list), but you can conceptualize range(1,7)
as a function that returns a list of numbers in that range. e.g.
range(1,7) ~~ [1, 2, 3, 4, 5, 6]
If your amount is an integer, you want to see if it's in that range, not if it is that range - after all, an integer cannot be a list at the same time.
[edit]: As one of the other answers pointed out, you might also want to cast the result of your input()
to an int - as input()
generally returns a string.
1
amount
isn't anint
, though. You're close.
– Makoto
Nov 15 '18 at 5:00
def quantity(): global amount amount = input('How many tickets are you looking for? ') if amount in range(1,7): print('You have selected tickets '.format(amount)) elif amount == (0): print('You have selected 0 tickets') else: print('Please choose an amount between 0-6') amount = int(amount)
So I added the if ... in and turned amount into an integer but still receive only the else part.
– WalkingLick
Nov 15 '18 at 5:09
You need to putamount = int(amount)
before you do theif
condition, not after. You could even wrap theinput()
statement in anint()
call
– Green Cloak Guy
Nov 15 '18 at 5:15
I understand now, thank you for the help.
– WalkingLick
Nov 15 '18 at 5:18
add a comment |
You want
if amount in range(1,7):
rather than what you currently have,
if amount == range(1,7):
It's a bit more complicated in reality (because it returns a generator rather than a list), but you can conceptualize range(1,7)
as a function that returns a list of numbers in that range. e.g.
range(1,7) ~~ [1, 2, 3, 4, 5, 6]
If your amount is an integer, you want to see if it's in that range, not if it is that range - after all, an integer cannot be a list at the same time.
[edit]: As one of the other answers pointed out, you might also want to cast the result of your input()
to an int - as input()
generally returns a string.
You want
if amount in range(1,7):
rather than what you currently have,
if amount == range(1,7):
It's a bit more complicated in reality (because it returns a generator rather than a list), but you can conceptualize range(1,7)
as a function that returns a list of numbers in that range. e.g.
range(1,7) ~~ [1, 2, 3, 4, 5, 6]
If your amount is an integer, you want to see if it's in that range, not if it is that range - after all, an integer cannot be a list at the same time.
[edit]: As one of the other answers pointed out, you might also want to cast the result of your input()
to an int - as input()
generally returns a string.
edited Nov 15 '18 at 5:01
answered Nov 15 '18 at 4:59
Green Cloak GuyGreen Cloak Guy
3,2651721
3,2651721
1
amount
isn't anint
, though. You're close.
– Makoto
Nov 15 '18 at 5:00
def quantity(): global amount amount = input('How many tickets are you looking for? ') if amount in range(1,7): print('You have selected tickets '.format(amount)) elif amount == (0): print('You have selected 0 tickets') else: print('Please choose an amount between 0-6') amount = int(amount)
So I added the if ... in and turned amount into an integer but still receive only the else part.
– WalkingLick
Nov 15 '18 at 5:09
You need to putamount = int(amount)
before you do theif
condition, not after. You could even wrap theinput()
statement in anint()
call
– Green Cloak Guy
Nov 15 '18 at 5:15
I understand now, thank you for the help.
– WalkingLick
Nov 15 '18 at 5:18
add a comment |
1
amount
isn't anint
, though. You're close.
– Makoto
Nov 15 '18 at 5:00
def quantity(): global amount amount = input('How many tickets are you looking for? ') if amount in range(1,7): print('You have selected tickets '.format(amount)) elif amount == (0): print('You have selected 0 tickets') else: print('Please choose an amount between 0-6') amount = int(amount)
So I added the if ... in and turned amount into an integer but still receive only the else part.
– WalkingLick
Nov 15 '18 at 5:09
You need to putamount = int(amount)
before you do theif
condition, not after. You could even wrap theinput()
statement in anint()
call
– Green Cloak Guy
Nov 15 '18 at 5:15
I understand now, thank you for the help.
– WalkingLick
Nov 15 '18 at 5:18
1
1
amount
isn't an int
, though. You're close.– Makoto
Nov 15 '18 at 5:00
amount
isn't an int
, though. You're close.– Makoto
Nov 15 '18 at 5:00
def quantity(): global amount amount = input('How many tickets are you looking for? ') if amount in range(1,7): print('You have selected tickets '.format(amount)) elif amount == (0): print('You have selected 0 tickets') else: print('Please choose an amount between 0-6') amount = int(amount)
So I added the if ... in and turned amount into an integer but still receive only the else part.– WalkingLick
Nov 15 '18 at 5:09
def quantity(): global amount amount = input('How many tickets are you looking for? ') if amount in range(1,7): print('You have selected tickets '.format(amount)) elif amount == (0): print('You have selected 0 tickets') else: print('Please choose an amount between 0-6') amount = int(amount)
So I added the if ... in and turned amount into an integer but still receive only the else part.– WalkingLick
Nov 15 '18 at 5:09
You need to put
amount = int(amount)
before you do the if
condition, not after. You could even wrap the input()
statement in an int()
call– Green Cloak Guy
Nov 15 '18 at 5:15
You need to put
amount = int(amount)
before you do the if
condition, not after. You could even wrap the input()
statement in an int()
call– Green Cloak Guy
Nov 15 '18 at 5:15
I understand now, thank you for the help.
– WalkingLick
Nov 15 '18 at 5:18
I understand now, thank you for the help.
– WalkingLick
Nov 15 '18 at 5:18
add a comment |
Try this code use in for ==
def quantity():
global amount
amount = input('How many tickets are you looking for? ')
if amount in range(1,7):
print('You have selected tickets '.format(amount))
elif amount == (0):
print('You have selected 0 tickets')
else:
print('Please choose an amount between 0-6')
add a comment |
Try this code use in for ==
def quantity():
global amount
amount = input('How many tickets are you looking for? ')
if amount in range(1,7):
print('You have selected tickets '.format(amount))
elif amount == (0):
print('You have selected 0 tickets')
else:
print('Please choose an amount between 0-6')
add a comment |
Try this code use in for ==
def quantity():
global amount
amount = input('How many tickets are you looking for? ')
if amount in range(1,7):
print('You have selected tickets '.format(amount))
elif amount == (0):
print('You have selected 0 tickets')
else:
print('Please choose an amount between 0-6')
Try this code use in for ==
def quantity():
global amount
amount = input('How many tickets are you looking for? ')
if amount in range(1,7):
print('You have selected tickets '.format(amount))
elif amount == (0):
print('You have selected 0 tickets')
else:
print('Please choose an amount between 0-6')
answered Nov 15 '18 at 4:58
vishalkvishalk
15117
15117
add a comment |
add a comment |
You have to convert the input()
from a string into an integer, otherwise you will always run the else statement. You can do that with int()
, but will likely have to do some error handling in case the user enters something that cannot be converted to an integer.
add a comment |
You have to convert the input()
from a string into an integer, otherwise you will always run the else statement. You can do that with int()
, but will likely have to do some error handling in case the user enters something that cannot be converted to an integer.
add a comment |
You have to convert the input()
from a string into an integer, otherwise you will always run the else statement. You can do that with int()
, but will likely have to do some error handling in case the user enters something that cannot be converted to an integer.
You have to convert the input()
from a string into an integer, otherwise you will always run the else statement. You can do that with int()
, but will likely have to do some error handling in case the user enters something that cannot be converted to an integer.
answered Nov 15 '18 at 4:59
rushinstuffinrushinstuffin
785
785
add a comment |
add a comment |
I have made some changes to your code. I believe this is what you are looking for.
def quantity():
global amount
amount = int(input('How many tickets are you looking for? '))
if amount in range(1,7):
print('You have selected tickets '.format(amount))
elif amount ==0 :
print('You have selected 0 tickets')
else:
print('Please choose an amount between 0-6')
add a comment |
I have made some changes to your code. I believe this is what you are looking for.
def quantity():
global amount
amount = int(input('How many tickets are you looking for? '))
if amount in range(1,7):
print('You have selected tickets '.format(amount))
elif amount ==0 :
print('You have selected 0 tickets')
else:
print('Please choose an amount between 0-6')
add a comment |
I have made some changes to your code. I believe this is what you are looking for.
def quantity():
global amount
amount = int(input('How many tickets are you looking for? '))
if amount in range(1,7):
print('You have selected tickets '.format(amount))
elif amount ==0 :
print('You have selected 0 tickets')
else:
print('Please choose an amount between 0-6')
I have made some changes to your code. I believe this is what you are looking for.
def quantity():
global amount
amount = int(input('How many tickets are you looking for? '))
if amount in range(1,7):
print('You have selected tickets '.format(amount))
elif amount ==0 :
print('You have selected 0 tickets')
else:
print('Please choose an amount between 0-6')
answered Nov 15 '18 at 5:03
NishilNishil
22518
22518
add a comment |
add a comment |
Instead of using if amount == range(1,7):
use if amount in range(1,7):
This is the modified code that you should use:
def quantity():
global amount
amount = input('How many tickets are you looking for? ')
if amount in range(1,7):
print('You have selected tickets '.format(amount))
elif amount == (0):
print('You have selected 0 tickets')
else:
print('Please choose an amount between 0-6')
add a comment |
Instead of using if amount == range(1,7):
use if amount in range(1,7):
This is the modified code that you should use:
def quantity():
global amount
amount = input('How many tickets are you looking for? ')
if amount in range(1,7):
print('You have selected tickets '.format(amount))
elif amount == (0):
print('You have selected 0 tickets')
else:
print('Please choose an amount between 0-6')
add a comment |
Instead of using if amount == range(1,7):
use if amount in range(1,7):
This is the modified code that you should use:
def quantity():
global amount
amount = input('How many tickets are you looking for? ')
if amount in range(1,7):
print('You have selected tickets '.format(amount))
elif amount == (0):
print('You have selected 0 tickets')
else:
print('Please choose an amount between 0-6')
Instead of using if amount == range(1,7):
use if amount in range(1,7):
This is the modified code that you should use:
def quantity():
global amount
amount = input('How many tickets are you looking for? ')
if amount in range(1,7):
print('You have selected tickets '.format(amount))
elif amount == (0):
print('You have selected 0 tickets')
else:
print('Please choose an amount between 0-6')
answered Nov 15 '18 at 5:07
Siddharth SatpathySiddharth Satpathy
6291817
6291817
add a comment |
add a comment |
input
returns a string, so I guess you should be doing amount = int(input('...'))
.
Am I missing something? Ahh... thein
not==
is also important... but I don't think that was the main concern of OP.
– Emil Vatai
Nov 15 '18 at 5:04
add a comment |
input
returns a string, so I guess you should be doing amount = int(input('...'))
.
Am I missing something? Ahh... thein
not==
is also important... but I don't think that was the main concern of OP.
– Emil Vatai
Nov 15 '18 at 5:04
add a comment |
input
returns a string, so I guess you should be doing amount = int(input('...'))
.
input
returns a string, so I guess you should be doing amount = int(input('...'))
.
answered Nov 15 '18 at 4:59
Emil VataiEmil Vatai
1,0941013
1,0941013
Am I missing something? Ahh... thein
not==
is also important... but I don't think that was the main concern of OP.
– Emil Vatai
Nov 15 '18 at 5:04
add a comment |
Am I missing something? Ahh... thein
not==
is also important... but I don't think that was the main concern of OP.
– Emil Vatai
Nov 15 '18 at 5:04
Am I missing something? Ahh... the
in
not ==
is also important... but I don't think that was the main concern of OP.– Emil Vatai
Nov 15 '18 at 5:04
Am I missing something? Ahh... the
in
not ==
is also important... but I don't think that was the main concern of OP.– Emil Vatai
Nov 15 '18 at 5:04
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.
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%2f53312657%2fif-statement-only-printing-else%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
Possible duplicate of How can I read inputs as integers?
– tripleee
Nov 15 '18 at 4:59
1
@tripleee: The dupe you're suggesting doesn't cover the comparison to a
range
value, but you're about halfway there.– Makoto
Nov 15 '18 at 5:00
@Makoto but that wasn't the main concern of OP, the question was why do both IF and ELIF fail, and the reason is covered in the duplicate. i.e. without conversion ELIF alway fails, with conversion it is true for 0.
– Emil Vatai
Nov 15 '18 at 5:10