Made script, but when I try to execute terminal opens and closes
Discuss Made script, but when I try to execute terminal opens and closes in the Python Programming forum on Dev Shed. Made script, but when I try to execute terminal opens and closes Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
Receive the tools necessary to be the rock star of your field. Our 12-month program teaches you the evolving world of multi-channel marketing as well as the complex issues and opportunities found in the industry.
ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month! Download and Activate to enter!
Web development can be a daunting task, even for specialists. There is a lot of information to absorb and a lot of technologies to learn in order to manage a superior website. When trying to learn the ropes, developers need a reliable source to introduce new ideas that can be easily implemented. When working on large projects, even web veterans may run into a technology or an aspect of a technology that they are unfamiliar with.
Posts: 1,075
Time spent in forums: 4 Weeks 1 Day 4 h 41 m 27 sec
Reputation Power: 98
Yes.
Maybe this program will give you the insight you need to continue as a python programmer. Your program is "right but backward". It's like looking at a magnetic compass and misunderstanding which of the two ends of the bar magnet points north. Instead of heading east you proceed west. As numerical methods go, you have to work harder to obtain good roots. Suppose the coefficient a is tiny and the parabola sinks just below y=0. Slight changes in the coefficients cause big changes to the roots. Try to picture the situation I described.
Oh, except for the backslashes at the line ends. NEVER use backslashes at the end of a line of python. You can always find a better way to continue a statement onto (the
next line.)
Code:
#!/usr/bin/env python
a = float(input("a=? ")) # assign to variable a the value from keyboard
b = float(input("b=? "))
c = float(input("c=? "))
import cmath,math
discriminant = b * b - 4 * a * c
if discriminant < 0:
q = cmath.sqrt(discriminant)
else:
q = math.sqrt(discriminant)
# more simply, q = discriminant**0.5
xb = (-b + q) / 2
xe = (-b - q) / 2
print('roots:')
print('\t',xb)
print('\t',xe)
Posts: 7
Time spent in forums: 1 h 41 m 46 sec
Reputation Power: 0
Quote:
Originally Posted by b49P23TIvg
Maybe this program will give you the insight you need to continue as a python programmer. Your program is "right but backward". It's like looking at a magnetic compass and misunderstanding which of the two ends of the bar magnet points north. Instead of heading east you proceed west. As numerical methods go, you have to work harder to obtain good roots. Suppose the coefficient a is tiny and the parabola sinks just below y=0. Slight changes in the coefficients cause big changes to the roots. Try to picture the situation I described.
Oh, except for the backslashes at the line ends. NEVER use backslashes at the end of a line of python. You can always find a better way to continue a statement onto (the
next line.)
Code:
#!/usr/bin/env python
a = float(input("a=? ")) # assign to variable a the value from keyboard
b = float(input("b=? "))
c = float(input("c=? "))
import cmath,math
discriminant = b * b - 4 * a * c
if discriminant < 0:
q = cmath.sqrt(discriminant)
else:
q = math.sqrt(discriminant)
# more simply, q = discriminant**0.5
xb = (-b + q) / 2
xe = (-b - q) / 2
print('roots:')
print('\t',xb)
print('\t',xe)
Ooh yea lots better, however
multiplying discriminant by 0,5 and then divide it by 2, isnt that double?
Posts: 1,075
Time spent in forums: 4 Weeks 1 Day 4 h 41 m 27 sec
Reputation Power: 98
oh---you're using a microsoft product. I think there's some sort of preference setting that keeps the console window open. Or you can run your code in idle (See www.python.org if you don't know about idle.) I usually run my programs in an emacs shell buffer. (xemacs might work better on microsoft windows system.)
Posts: 7
Time spent in forums: 1 h 41 m 46 sec
Reputation Power: 0
Quote:
Originally Posted by b49P23TIvg
oh---you're using a microsoft product. I think there's some sort of preference setting that keeps the console window open. Or you can run your code in idle (See (site i cant quote) if you don't know about idle.) I usually run my programs in an emacs shell buffer. (xemacs might work better on microsoft windows system.)
No not really, actually im using Ubuntu 11.10 and I'm running this program in Ubuntu's terminal.
But since I added the sleep command it doesnt exit anymore.
Currently busy searching for a way to restart the program.