Scorcheddd Posted July 17, 2011 Share Posted July 17, 2011 Hey guys, I'm a future computer science student but I need a bit of help. Can anyone recommend me any good step by step guides/books/textbooks that will help me learn it? My teacher this fall assigned us Python Programming: an introduction to computer science, but every time I type the examples into IDLE, they don't work. I've checked my syntax at least 15 times, entirely typing the script again and comparing side by side to no avail. It keeps saying there are errors when I have exactly what the author initially put down in the book. So any GOOD tutorials/books are greatly appreciated, thanks! Link to comment Share on other sites More sharing options...
obfuscator Posted July 17, 2011 Share Posted July 17, 2011 What error is it giving you? Be specific. You'll also have to be more specific about exactly what kind of books you want. Python in particular? "It's not a rest for me, it's a rest for the weights." - Dom Mazzetti Link to comment Share on other sites More sharing options...
Scorcheddd Posted July 19, 2011 Author Share Posted July 19, 2011 Sorry, I'm studying python first so those are the kinds of books and tutorials I'm looking for. But here's one of the codes, written the same as the book, and it keeps getting a syntax error. # quadratic.py # A program that computes the real roots of a quadratic equation. # Illustrates use of the math library. # Note: this program crashes if the equation has no real roots import math # makes the math library available def main(): print("This program finds the real solutions to a quadratic") print() a,b,c=eval(input("Please enter the coefficients(a,b,c): ") discRoot=math.sqrt(b*b-4*a*c) root1=(-b+discRoot)/(2*a) root2=(-b-discRoot)/(2*a) print() print("The solutions are: ",root1,root2) main() The first discRoot there keeps giving me an error... Link to comment Share on other sites More sharing options...
obfuscator Posted July 19, 2011 Share Posted July 19, 2011 What's the error that you get? Just looking at it, you may need to convert the parameters a,b, and c to floats. "It's not a rest for me, it's a rest for the weights." - Dom Mazzetti Link to comment Share on other sites More sharing options...
Markup Posted July 20, 2011 Share Posted July 20, 2011 For a start, the main problem is that your input line is missing a ')'.You need to use raw_input() instead of input()And you should not use IDLE for implementations, only for testing new functions / odd bits. Set up your environment variable paths, and run your code from cmd, much easier. import math # makes the math library available def main(): print("This program finds the real solutions to a quadratic") print() a,b,c = eval(raw_input("Please enter the coefficients(a,b,c): ")) discRoot=math.sqrt((b*b)-(4*a*c)) root1=(-b+discRoot)/(2*a) root2=(-b-discRoot)/(2*a) print() print("The solutions are: ",root1,root2) main() Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now