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 5 days ago.
Improve this question
I have a Python script that is not evaluating as expected in the IF statement.
Here is the code. I am new to Python, so it's probably a simple mistake I am making.
php script being posted to:
<?php
echo "0";
?>
Python script:
r = requests.post(url, data = data, headers = headers)
print(f'Result is [{r.text}]')
#I SEE THE CORRECT OUTPUT OF: Result is [0]
if r.text == 0: print("R is 0")
#EXPECTED RESULT: R is 0
The issue is that the IF statement comes out False.
I printed out r.text to make sure it is equal to 0 and I get the expected result of "Result is [0]". Any help or suggestions would be appreciated
Just figured it out, in case someone else has same issue.
r = requests.post(url, data = data, headers = headers)
print(f'Result is [{r.text}]')
result = int(r.text)
if r.text == 0: print("R is 0")
Had to convert the result from a string to an int
Related
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
def kaka(name):
r=''
for ch in name:
r=r+ch*3
return r
Output:
>>> kaka('Mississippi')
>>> 'MMMiiissssssiiissssssiiippppppiii'
But for this code:
def kaka(name):
for ch in name:
r=''
r=r+ch*3
return r
I am getting output as: iii
That's because in your second code you're re-assigning r back to the empty string ''. Thus you only get the final character multiplied 3 times (which for Mississippi is i).
You are getting 2 different outputs because in the first code you are initialising the value of r i.e r = '' outside the for loop and in the second program you are initialising value of r inside the for loop.
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 4 years ago.
Improve this question
Solved: Thanks for your helps. i'm working dictionary and hash codes in one page, and there was a block problem. i thought, my logic is wrong but i checked all page, and i fixed blocks. its works fine right now.
Here's my problem:
d = {}
d['a'] = 'alpha'
d['b'] = 'beta'
missing_key = 'x' in d
if missing_key == True:
print ("The key, you are looking for was successfully found!")
else:
print ("The key, you are looking for was not found!")
print ("Here are keys in database:")
for k, r in enumerate(d.keys(), start=1)
print ("Key {}: {}".format(k, r))
that for condition works perfectly. but i cant run that if condition. Where am i doing wrong ? Thanks for your help.
Getting this error:
File "C:/Python/dictionary-hash.py", line 33
if missing_key == True:
IndentationError: unexpected indent
also i'm using "Python 3.6" and "Anaconda Spyder"
There's nothing wrong with the logic in your code. Since the error is an IndentationError, it must be because you're using inconsistent indentation on that if line. Make sure that the indentation on each line is consistent (using same number of spaces/tabs). Probably there is a space at the beginning of that line that is causing the error.
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 4 years ago.
Improve this question
I'm iterating through all the img's in a request.POST to see if they are HTTPS (I'm using Beautiful Soup to help)
Here's my code:
content = request.POST['content']
print(content) #prints:
<p>test test test</p><br><p><img src="https://www.treefrogfarm.com/store/images/source/IFE_A-K/ClarySage2.jpg" alt=""></p><br><p>2nd 2nd</p><br><p><img src="https://www.treefrogfarm.com/store/images/source/IFE_A-K/ClarySage2.jpg" alt=""></p>
soup = BeautifulSoup(content, 'html.parser')
for image in soup.find_all('img'):
print('Source:', image.get('src')[:8]) #prints Source: https://
if image.get('src')[:7] == "https://":
print('HTTPS')
else:
print('Not HTTPS')
Even though image.get('src')[:7] == "https://", the code still prints Not HTTPS.
Any idea why?
Well for starters, 'https://' is 8 characters, so there's no way that a slice of 7 characters can match it.
Also, please make your question titles actually indicative of the problem you're having rather than unrelated accusations about the python operators.
to match the https:// string the appropriate slice would be :8 instead of :7
if image.get('src')[:8] == "https://":
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 8 years ago.
Improve this question
I'm new to python so this may be a beginner question. My 'else' statement in the code below gets a syntax error for a reason beyond my mind. I've looked up the syntax for it multiple times but I cannot find the error. This is my python code:
siteswap = input("Enter the siteswap you want to validate here:")
aantal_digits = len(siteswap)
i = 0
j = 1
while i != aantal_digits:
if (int(siteswap[i])+ (i + 1)) % aantal_digits == (int(siteswap[1:aantal_digits])+ (j + 1)) % aantal_digits:
print("This siteswap is invalid")
break
elif i != aantal_digits:
del (int(siteswap[i])
else:
print ("This siteswap is valid")
break
The else is highlighted and I get a "syntax error".
Your problem is
del (int(siteswap[i])
You are missing a closing parenthesis (but the parenthesis are unnecessary in the first place). Also, del int(siteswap[i]) will not work, because you cannot delete function calls: SyntaxError: can't delete function call
del siteswap[i]
will delete the actual item from your array.
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 7 years ago.
Improve this question
I am performing one python program and the part of the code is as follows
while 1:
data = conn.recv(BUFFER_SIZE)
if not data: break
print "received data:", data
com = "echo " + data
print com
conn.send(data)
conn.close()
but when i am trying to execute the code i am getting the following error.
File "server.py", line 17
com = "echo " + data
^
IndentationError: unexpected indent
I am not getting whats wrong with the code above.
check that you either consistently have tabs or spaces not a mix of both.