When you're evaluating -12**2 you're essentially evaluating -(12**2).
And also, (-12) squared is always 144.
If you want to retain the sign use -(12**2). If you don't want the sign to be retained, use (-12)**2
If you're trying to evaluate the square root of a negative number. It is going to be the same as the sqrt of the positive number multiplied by imaginary i
Just evaluate negative numbers the same way you would positive numbers, and append i to it.
In your particular case, the min function is screwing things up when you evalute negative numbers
Should I use answer = 0 - var or is answer = -var enough?
For those of you familiar with finance: I have the term S from black-scholes model set to the variable s, and depending on whether i say to value a call or a put, I will use s or -s
working with negative numbers in python - Stack Overflow
How to convert positive numbers to negative in Python? - Stack Overflow
python - Space between negative sign and variable name - Software Engineering Stack Exchange
How to assign negative numbers in python
Perhaps you would accomplish this with something to the effect of
text = raw_input("please give 2 numbers to multiply separated with a comma:")
split_text = text.split(',')
a = int(split_text[0])
b = int(split_text[1])
# The last three lines could be written: a, b = map(int, text.split(','))
# but you may find the code I used a bit easier to understand for now.
if b > 0:
num_times = b
else:
num_times = -b
total = 0
# While loops with counters basically should not be used, so I replaced the loop
# with a for loop. Using a while loop at all is rare.
for i in xrange(num_times):
total += a
# We do this a times, giving us total == a * abs(b)
if b < 0:
# If b is negative, adjust the total to reflect this.
total = -total
print total
or maybe
a * b
Too hard? Your TA is... well, the phrase would probably get me banned. Anyways, check to see if numb is negative. If it is then multiply numa by -1 and do numb = abs(numb). Then do the loop.
I couldn't find anything about it in the Python style guide, as you said, but searching for "unary operator spacing" brought more hits from various languages, such as this for Javascript:
No space should separate a unary operator and its operand except when the operator is a word such as typeof.
Or this for C:
Don't use spaces around unary operators, except sizeof and casts
In the Linux kernel:
Use one space around (on each side of) most binary and ternary operators, [...] but no space after unary operators:
Note that a writing style for code, which is usually written with a fixed-width font and mostly Latin characters, is quite different than that for equations, where you can find both latin and greek letters, topological constructs such as fractions or those marks surrounding that epsilon you have there, and other things that make them a whole lot more complex than code.
I've run across this before, and I used
var false_positive = 0 - true_positive
to make sure the intent is clear. That is the more readable form.
i want python to randomly choose between 0.3 and -0.3,
but python dosent seem to take the negative number