Answer the question
In order to leave comments, you need to log in
How to convert a number greater than 6 to septimal number system?
There is the following line in the code:
Which gives an error:
ValueError: invalid literal for int() with base 7: '82'
How to fix this and convert numbers greater than 6 to septal number system?
int(str(82),7)
Answer the question
In order to leave comments, you need to log in
I found the solution myself https://www.cyberforum.ru/python-beginners/thread2...
def dec_to_base(N, base):
if not hasattr(dec_to_base, 'table'):
dec_to_base.table = '0123456789ABCDEF'
x, y = divmod(N, base)
return dec_to_base(x, base) + dec_to_base.table[y] if x else dec_to_base.table[y]
write a function to convert the number system of a number.
google and sprinkle on you such functions as from a cornucopia. figure it out, think about it, and do it for yourself.
This is what training is based on.
Copied code from https://www.quora.com/How-do-I-write-a-program-in-...
def convertToSimeric(number, targetBase=7):
newNum = ''
powers = []
for x in reversed(range(targetBase)):
powers.append(2**x)
for i, x in enumerate(powers):
if number - x >= 0:
newNum += '1'
number = number - x
else:
newNum += '0'
print(''.join(newNum))
Looked at the request more closely.
It seems to me that the main problem here is sorting the main table by a non-indexed field.
I suggest to start with making an index on the price field.
ALTER TABLE tasks ADD INDEX (status,price);
moreover, since reverse sorting is needed, and mysql does not support it in indexes, then store the price in negative values, and take it modulo when extracting. For now, just remove DESC from the query for tests.
Add another status to the tasks table (you have one, but it's not clear why you need it). Let it be the status1 field, which has the value 0 - if the task is not hidden and not completed, 1 - if it is hidden, 2 - if it is completed. Now you can take not hidden and not completed tasks simply by status, discarding two subrequests at once.
Did you make an explain request?
Using just IN is not very recommended, but you generally have IN (SELECT ...)
Explain your query and see how many rows are affected. In your case, it will be several million sorts.
Do as you are advised above. Add a field to tasks and make it an index. Make the field tinyint or set('done','hide') so that it doesn't take up much space.
Can you show what explain shows?
What version of mysql?
show my.cnf
Try adding an index
ALTER table tasks ADD index test_index (`id`, `status`, `price`, `name`);
Merge the done and hide tables into one, such as tasks_status
CREATE TABLE IF NOT EXISTS `tasks_status` (
`task_id` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`status` int(1) NOT NULL,
UNIQUE KEY `task_id_user_id` (`task_id`,`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question