Why does A resolve true, but B does not? [closed] - python-2.7

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 5 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
Why does A resolve true, but B does not?
Bosses = {
'A' : 5,
'B' : [5,6]
}
for key, value in Bosses.iteritems():
if value == 5:
print "Yes for " + key
else:
print "No for " + key

You could add an additional check like this
if (isinstance(value, list) and 5 in value) or value == 5:
print "Yes for " + key
else:
print "No for " + key

Related

trying to create password in c++ [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I am trying to do password handling in C++.
For example, I want the password to be 12345678, but no matter what I insert as a meaning of 'a' it always says that the password is correct, so basically it always thinks the quantity of 'a' is equal to the quantity of 'x'.
At the beginning, I tried to do it like this:
if (a = 12345678)
cout << "password is correct";
This didn't work either.
here is the picture of the code: https://imgur.com/ssl4i6F
The problem is a = 12345678 is operation that sets ato 12345678 and returns a by reference. So your if statement simply doesn't do what you want - instead of checking whether a is 12345678, it sets a to 12345678 and then checks if a isn't zero.
To fix it replace = with == for comparison.
if (a == 12345678)
cout << "password is correct";
Though, it is a bit strange that password is a number and not a string... but whatever.

Illegal expression in Else line [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
When I try to compilate my code a
"unit1.pas(53,1) Error: Illegal expression"
in else line appears.
procedure TForm1.Button1Click(Sender: TObject);
var x: real;
begin
x:=StrToFloat(Edit1.Text);
if x>=0
then
Label1.Caption= FloatToStr(x)
else
Label1.Caption:= Floattostr(x);
What's wrong is the expression before the else. You have an equals sign = where you ought to have an assignment operator :=, as you have in the else:
if x>=0 then
Label1.Caption := FloatToStr(x)
else
Label1.Caption:= Floattostr(x);

please suggest me what is wrong?? it only shows element not found [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
def binsearch(a,c):
first=0
last=len(a)-1
found=False
while first<=last and not found:
mid=(first+last)//2
if(a[mid]==c):
found=True
elif a[mid]<c:
last=mid-1
else:
first=mid+1
return found
a=list()
n=raw_input("Enter how many elements:")
for i in range(int(n)):
num=raw_input("Enter the elements:")
a.append(int(num))
c=raw_input("Enter the element u wanna search:")
b=binsearch(a,c)
if b:
print "Element",c,"found in position."
else:
print "Element not found."
The error is that c is a string.
Just add c = int(c) after the c = raw_input("...") line

My linked list is not working correctly [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
following is my code for the program that will print out the random position contained values of nodes of a linked list. The problem is that my list is not printing the complete result. It prints only one result and thus. Please tell me where i am wrong.
int main(){
List* n;
int value=3;
int *counter=0;
collect(value,counter);
for(int i=0; i<&counter; i++);
{
count<<"\n Shuffled: "<< n.pickanddestroy();
}
}
Remove the semicolon at the end of the first line of your for loop.

C++ character check [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I have just started to learn C++ and i would like to get some help.
The user needs to type an ID number and the format has to be the following. The first character B and the other 4 any integer.
Im trying to check if the character format are right.
So far i have this:
if ((isalpha(id[0])=='B' ) && (isdigit(id.at(1))) && (isdigit(id.at(2))) ......
{
//do something
}
else
{
cout << "Wrong format" << endl;
}
but even if i type example B8745 it says wrong format.
You are comparing the result of isalpha, which is boolean, to character literal 'B'.