Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming
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.

Learn More!


Download to Enter
| Contest Rules

Tutorials | Forums

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 26th, 2012, 09:30 AM
Duifmeneer Duifmeneer is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2012
Posts: 7 Duifmeneer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 41 m 46 sec
Reputation Power: 0
Made script, but when I try to execute terminal opens and closes

Hi there,

First I'd like to introduce myself.
My name is Duif and I'm totally new to programming
I've done some programming on my Graphic Calculator.

Here is the script
Code:
#!/usr/bin/env python
print("a=?") a =\ 
print("b=?") b =\ 
print("c=?") c =\ 
import math 
(-b + math.sqrt(b * b - 4 * a * c)) / 2 = xb 
(-b - math.sqrt(b * b - 4 * a * c)) / 2 = xe 
print(xb) 
print(xe)


Does anyone know what I did wrong?

Thanks,

Duif

Reply With Quote
  #2  
Old January 26th, 2012, 02:54 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Click here for more information.
 
Join Date: Aug 2011
Posts: 1,075 b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level)b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level)b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level)b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level)b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level)b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level)b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
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)

Reply With Quote
  #3  
Old January 26th, 2012, 04:21 PM
Duifmeneer Duifmeneer is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2012
Posts: 7 Duifmeneer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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?

Thanks a lot man

Duif

Reply With Quote
  #4  
Old January 26th, 2012, 04:31 PM
Duifmeneer Duifmeneer is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2012
Posts: 7 Duifmeneer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 41 m 46 sec
Reputation Power: 0
Nevermind, it works also added
Code:
import time
time.sleep(30)

Reply With Quote
  #5  
Old January 27th, 2012, 08:34 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Click here for more information.
 
Join Date: Aug 2011
Posts: 1,075 b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level)b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level)b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level)b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level)b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level)b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level)b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
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.)

Reply With Quote
  #6  
Old January 27th, 2012, 12:08 PM
Duifmeneer Duifmeneer is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2012
Posts: 7 Duifmeneer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #7  
Old January 27th, 2012, 12:22 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Click here for more information.
 
Join Date: Aug 2011
Posts: 1,075 b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level)b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level)b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level)b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level)b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level)b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level)b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 4 Weeks 1 Day 4 h 41 m 27 sec
Reputation Power: 98
I'm also using ubuntu. Hope I never duplicate your issue!

Reply With Quote
  #8  
Old January 27th, 2012, 12:30 PM
Duifmeneer Duifmeneer is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2012
Posts: 7 Duifmeneer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 41 m 46 sec
Reputation Power: 0
Quote:
Originally Posted by b49P23TIvg
I'm also using ubuntu. Hope I never duplicate your issue!


Do you mean that there's something wrong with my OS (or its terminal)?

Reply With Quote
  #9  
Old January 27th, 2012, 12:51 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Click here for more information.
 
Join Date: Aug 2011
Posts: 1,075 b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level)b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level)b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level)b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level)b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level)b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level)b49P23TIvg User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 4 Weeks 1 Day 4 h 41 m 27 sec
Reputation Power: 98
I presume you're using gnome terminal.

Next I presume the menu bar is turned on because I don't feel like figuring out which mouse/control key combination brings up this menu.

click Edit on the menu bar.

At the bottom find and click Profile Preferences.

This brings a window with several tabs. Click the Title and Command tab.

Change the "When command exits" behavior to suit your need.


Anyway, as I said, I use shell mode in emacs instead of these terminal windows.

Reply With Quote
  #10  
Old January 29th, 2012, 03:23 PM
Duifmeneer Duifmeneer is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2012
Posts: 7 Duifmeneer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 41 m 46 sec
Reputation Power: 0
Quote:
Originally Posted by b49P23TIvg
I presume you're using gnome terminal.

Next I presume the menu bar is turned on because I don't feel like figuring out which mouse/control key combination brings up this menu.

click Edit on the menu bar.

At the bottom find and click Profile Preferences.

This brings a window with several tabs. Click the Title and Command tab.

Change the "When command exits" behavior to suit your need.


Anyway, as I said, I use shell mode in emacs instead of these terminal windows.


Thanks a lot, I really appreciate the time you put in helping me out !,

Duif

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Made script, but when I try to execute terminal opens and closes


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.

© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 8 - Follow our Sitemap