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 4 years ago.
Improve this question
I am working on a python project, I have to realize a syntaxic parser complex numbers, I need to make a calculator for arithmetic operations. I want to know how to get started, can you help me please ?
You might get away with very little if you can accept individual operands one at a time. As you may well know, Python accepts 1+2j as a complex number, 5.36j as an imaginary number. Thus, most parsers are overkill for parsing single complex numbers, if you ask the user to input numbers in the conventional way (ie, 10.2+i6.57). Just do a little string processing to extract the real and imaginary parts and use the complex function.
I suggest:
Tk for the GUI
pyparsing, if you really want a parser but it's probably unnecessary
Python itself for doing the arithmetic
Possible exchange with user:
>>> x = 2+8j
>>> y = 3-7j
>>> x/y
(-0.8620689655172415+0.6551724137931035j)
>>> x*y
(62+10j)
Related
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
If code is divided into too many segments, can this make the program slow?
For example - Creating a separate file for just a single function.
In my case, I'm using Python, and suppose there are two functions that I need in the main.py file. If I placed them in different files (just containing the function).
(Suppose) Also, If I'm using the same library for the two functions and I've divided the functions into separate files.
How can this affect efficiency? (Machine performance-wise and Team-wise).
It depends on the language, the framework you use etc. However, dividing the code too much can make it unreadable, which is (most of the time) the bigger problem. Since most of the time you will (or should) be working in a team, you should consider how readable your code would be for them.
However, answering this in a definite way is difficult. You should ask a Senior developer on your team for guidelines.
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'm wondering how I can calculate powers of a complex number without using the complex numbers data type. So I have a function
def Power_complex(re, im, n):
How can I calculate (re + im * i)^n with this? Thank you!
You can use the Biniomial theorem for arbitrary exponents, although positive integers is the easiest case.
Or you can treat the problem in polar coordinates (this link simply gives you the answer, only click if you really don't want to figure it out on your own)
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 3 years ago.
Improve this question
I am implementing a toy db, and I need a free function that gives me a lexicophgraically bigger string each time it's called. It's for naming segment files.
Let's assume I have a max of 1000 files, and I'd prefer if the string was less than 10 characters long.
Could someone give me the easiest example of such a function in python? I'd really like to be a free function as I don't want to introduce complexity with state.
A function that returns a different value each time you call it will have to keep some sort of state. However, defining a generator makes that relatively simple to manage. Specifically, itertools.count will produce an infinite stream of increasing integers; you just need to produce a suitable string from each integer.
from itertools import count
next_label = map("{:010}".format, count()).__next__
Then
>>> next_label()
'0000000000'
>>> next_label()
'0000000001'
>>> next_label()
'0000000002'
and so on, for as many times as you need to call next_label.
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 4 years ago.
Improve this question
I am wondering what I should do for the purpose of my project.
I am gonna operate on about 100 000 rows, every time.
what I wanted to do is to create an object "{}" and then, if I need to search for a value, just call it , for example
data['2018']['09']['Marketing']['AccountName']
the second option is to pull everyting into an array "[]" and in case I need to pull value, I will create a function to go through the array and sum numbers for specific parameters.
But don't know which method is faster.
Will be thankful if you can shed some light on this
Thanks in advance,
If performance (speed) is an issue, Python might not be the ideal choice...
Otherwise:
Might I suggest the use of a proper database, such as SQLLite (which comes shipped with Python).
And maybe SQLAlchemy as an abstraction layer. (https://docs.sqlalchemy.org/en/latest/orm/tutorial.html)
After all, they were made exactly for this kind of tasks.
If that seems overkill: Have a look at Pandas.
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 4 years ago.
Improve this question
I want to get < from a string that contains the character.
So what I want to do is:
magic_function('<') = <
in order to make. For example:
1 magic_function('<') 3
I expect, of course, that the program returns True
This isn’t possible with specifically what you want. A function returns an object, not an operator. I’m not sure what your main intention is here but you might want to rethink your architecture.
What you can do (but what I don’t recommend) is using eval() like so:
eval(“1 < 3”)
But there are many resources online about why eval is “evil”: to sum them up, if you don’t know what your data source is, then you could be performing unexpected operations which you might not want.