"logical operator" behaves unexpectedly in python [closed] - python-3.x

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 1 year ago.
Improve this question
Why does the following behave unexpectedly in Python?
print('a' > 'b')
False
print('a' > 'A')
True

If you use >, <, >=, or <= on strings, they get compared by their ASCII value. The ASCII value of 'a' is 97, 'b' is 98, and 'A' is 65. So A is lower than a, because it's earlier in the ASCII table.

Related

Getting the sum of all uneven indices of an int [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 days ago.
Improve this question
I'm new to rust and tried writing a function that adds all digits at the uneven positions together (For context: I'm trying to solve this Daily programmer #370. But somehow my results are off by a bit and I can't wrap my head around what#s going on.
number.to_string().chars()
.enumerate()
.filter(|(i, _)| i % 2 != 0)
.map(|(_, c)| c as u64 - 48)
.sum::<u64>()
Now if I input 4210000526 I get 13 as a result, although I should get 15. For some reason this only happens with a filter for uneven positions, "i % 2 == 0" works perfectly fine.

Can I input a number in scientific notation? [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 last year.
Improve this question
I want to input a large number by scientific notation, for example of distance to sun.
distance = float(input("distance to sun?:"))
I tried to enter 1.471*10**11 and 1.471e11, but both said "could not convert string to float"
Do I have to type the multiple "0"? Thanks for answering in advance.

How can I access the 1st element of a nested list? [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 1 year ago.
Improve this question
I have a nested list and I want to pull out the first element of every list of lists:
t = [
[['a',1],['b',2],['c',3]],
[['d',1],['e',2],['f',3]],
[['g',1],['h',2],['i',3]]
]
want = ['a','d','g']
I am getting the Comphrension wrong:
list = [x[0][0] for x in t]
It will work as long as you don't call your variable 'list' (call it 'new_t' or whatever) - list is a reserved word in python.

invalid token with hex() [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 have a set of binary number, some of them start with 0, for example:
000000000001
When I use hex(000000000001) I get the following error:
>>> hex(0000000000000001)
File "<stdin>", line 1
hex(0000000000000001)
^
SyntaxError: invalid token
But I dont have with :
>>> hex(0000000000000000)
'0x0'
How to pass some digit if they start with zero?
You have to do the following steps:
string_of_bits = '0b' + '000000000001'
hex(int(string_of_bits,2))

RANDBETWEEN excel function giving errors [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 7 years ago.
Improve this question
I'm pasting in the formula:
=RANDBETWEEN(DATE(2014, 1, 1),DATE(2015, 1, 1))
which is mentioned in several tutorials but getting the Excel "error with function message". I'm in Ireland which is a different format but either way it doesn't work.
Anything else I have to do to generate random dates?
Try :
=RANDBETWEEN(41640,42005)
And format as date.
For some countries:
=RANDBETWEEN(41640;42005)
And format as date.
And if the 2nd works maybe just:
=RANDBETWEEN(DATE(2014; 1; 1);DATE(2015; 1; 1))

Resources