Jump to content
Due to the significant updates that have taken place, you now need to login with your display name or e-mail address, NOT your login name. ×
Due to posts that are 5+ years old being rebuilt, some of the older BBCodes may not have converted properly but still be in the post. Most posts are unaffected but some using what was our custom BBCode (like [spoiler]) will be a bit broken. ×
Sign in to follow this  
Scorcheddd

Studying Computer Science in College, help

Recommended Posts

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!

Share this post


Link to post
Share on other sites

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?


polvCwJ.gif
"It's not a rest for me, it's a rest for the weights." - Dom Mazzetti

Share this post


Link to post
Share on other sites

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...

Share this post


Link to post
Share on other sites

What's the error that you get?

 

Just looking at it, you may need to convert the parameters a,b, and c to floats.


polvCwJ.gif
"It's not a rest for me, it's a rest for the weights." - Dom Mazzetti

Share this post


Link to post
Share on other sites

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()

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.