Can't understand why the code shows incorrect output. The output should be 1 and yes but instead of yes it shows NoConvert bytes to a string?Filters in Python3Why Is the Output of My Range Function Not a List?zip function giving incorrect outputWhy does list in program give an unexpected output?Python zip function - weird resultWhy is output not printing a list?python code running else statement even after if statement is trueWhy is the else statement in this code not working?Concatenate arrays in Python - output error
Can I enter the UK without my husband if we said we'd travel together in our visa application?
Is it acceptable to say that a reviewer's concern is not going to be addressed because then the paper would be too long?
Convex hull in a discrete space
What does Sartre mean by "pédéraste" - pederast or homosexual?
Difference between "rip up" and "rip down"
Number of list elements less than a given integer
Why was it decided in 1956 to abolish the spelling чорт (devil) in favor of чёрт?
I reverse the source code, you reverse the input!
What does מעלה עליו הכתוב mean?
How to check if my quadrature encoder is broken or not?
Is the order of words purely based on convention?
Why, even after his imprisonment, people keep calling Hannibal Lecter "Doctor"?
What exactly did this mechanic sabotage on the American Airlines 737, and how dangerous was it?
New road bike: alloy dual pivot brakes work poorly
Why are there two fundamental laws of logic?
Flowers sent by the birds
Align all symbols in a LaTeX equation
Why is STARTTLS still used?
Designing a time thief proof safe
Help in drawing resonance structures in case of polybasic acids
Why is a road bike faster than a city bike with the same effort? How much faster it can be?
Comma Code - Automate the Boring Stuff with Python
Seventh degree polynomial
Is a Middle Name a Given Name?
Can't understand why the code shows incorrect output. The output should be 1 and yes but instead of yes it shows No
Convert bytes to a string?Filters in Python3Why Is the Output of My Range Function Not a List?zip function giving incorrect outputWhy does list in program give an unexpected output?Python zip function - weird resultWhy is output not printing a list?python code running else statement even after if statement is trueWhy is the else statement in this code not working?Concatenate arrays in Python - output error
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
Iam learning python and wanted to test the concept of list and if/else function.
num1 = ["1"]
c = num1[0]
print(c)
if num1[0] == 1:
print("yes")
else:
print("no")
I expect the output to be 1 yes
but I get the output as 1 no
why does it not enter if block even when the condition is met
python-3.x
add a comment
|
Iam learning python and wanted to test the concept of list and if/else function.
num1 = ["1"]
c = num1[0]
print(c)
if num1[0] == 1:
print("yes")
else:
print("no")
I expect the output to be 1 yes
but I get the output as 1 no
why does it not enter if block even when the condition is met
python-3.x
add a comment
|
Iam learning python and wanted to test the concept of list and if/else function.
num1 = ["1"]
c = num1[0]
print(c)
if num1[0] == 1:
print("yes")
else:
print("no")
I expect the output to be 1 yes
but I get the output as 1 no
why does it not enter if block even when the condition is met
python-3.x
Iam learning python and wanted to test the concept of list and if/else function.
num1 = ["1"]
c = num1[0]
print(c)
if num1[0] == 1:
print("yes")
else:
print("no")
I expect the output to be 1 yes
but I get the output as 1 no
why does it not enter if block even when the condition is met
python-3.x
python-3.x
edited Mar 28 at 19:18
Paandittya
6395 silver badges16 bronze badges
6395 silver badges16 bronze badges
asked Mar 28 at 18:41
Prnv_atPrnv_at
1
1
add a comment
|
add a comment
|
1 Answer
1
active
oldest
votes
Arent you comparing string with integer? try if (num[0]=="1")
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/4.0/"u003ecc by-sa 4.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%2f55404763%2fcant-understand-why-the-code-shows-incorrect-output-the-output-should-be-1-and%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Arent you comparing string with integer? try if (num[0]=="1")
add a comment
|
Arent you comparing string with integer? try if (num[0]=="1")
add a comment
|
Arent you comparing string with integer? try if (num[0]=="1")
Arent you comparing string with integer? try if (num[0]=="1")
answered Mar 28 at 18:44
MurksiukeMurksiuke
315 bronze badges
315 bronze badges
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.
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%2f55404763%2fcant-understand-why-the-code-shows-incorrect-output-the-output-should-be-1-and%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