Python: 'float' object cannot be interpreted as an integer? [closed] - python

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am getting an error TypeError: 'float' object cannot be interpreted as an integerin this part of my code. Can someone tell me why am I getting the error and how to fix it?
for y in range(-x/2, x/2):
#Some function

Replace -x/2 with -int(x/2) and x/2 with int(x/2). Division in Python returns a float and range only takes ints.

Related

Python make list from string [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I have column with this kind of data:
I want to count how many times valu occur in a row. It is a string, so I want to convert this '63,63,63,63,63,63,63,63,63,63,63' to this ['63','63','63'...].
I there any way to do this quickly?
Thanks
if given string is s
l=s.split(',')
l is the required list

Example of XOR Operator in Python [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Can someone give a suitable example of the XOR Operator in Python ? I understand its definition but couldn’t implement it. So, please explain with a suitable example.
Thanks in advance
This is a fair enough implementation:
def xor(a:bool, b:bool)->bool:
return (not a) == (b)

What are the various ways to iterate over map() function other than list [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Suppose I have the some code in which I used map() function.
I know I can later print it by converting it to list just like this :
get_something = map(some_function, some_list)
print(list(get_something))
But Is there any way other than list. I mean what if I want to print not as list but line by line and don't want to use for loop every now and then?
Why dont you try this:
print(*map(some_function, some_list),sep='\n')
By this print() will refer to map object and will print values with \n as a separator

How to divide years in half a year in python? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
How should I do to divide years in half a year in this case if running in Python code?
I wasn't sure if you wanted horizontal or vertical divisions so I gave you both.
More practically, maybe this answer will help?
Creating numpy linspace out of datetime
You can specify start and end date and the number of divisions.

Convert ASCII strings to Hex strings in Python [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
How can I convert ASCII strings to Hex strings in Python ? Is there any built in function I can use for this ?
It depends on exactly what you mean by "ASCII to hex", but you should be able to adapt this approach to get whatever you're looking for:
>>> foo = "foo"
>>> ''.join(hex(ord(c))[2:] for c in foo)
'666f6f'

Categories