Difference between revisions of "Quadratic Formula Assignment"

From WLCS
Line 1: Line 1:
 
'''Objective:'''  
 
'''Objective:'''  
 
* You will create a program that calculates the quadratic formula from given user input
 
* You will create a program that calculates the quadratic formula from given user input
 +
 +
'''Resources:'''
 +
* [http://openbookproject.net/thinkcs/python/english2e/ch02.html How to Think Like a Computer Scientist: Chapter 2]
 +
* [http://en.wikipedia.org/wiki/Quadratic_equation#Quadratic_formula Quadratic Formula]
  
 
'''Directions:'''
 
'''Directions:'''
# Create a program, where you prompt the user (ask the user for input) for variables a, b, and c  
+
# Create a program named '''quad.py'''
 +
# Prompt the user (ask the user for input) for variables a, b, and c
 
# Calculate both real solutions using the quadratic formula (look it up on the internets)
 
# Calculate both real solutions using the quadratic formula (look it up on the internets)
## Reminder: There are two roots to calculate
+
#* There are two roots to calculate
## HINT: exponentiation: x**y (x to the y power)
+
#* You should have two variables x1 and x2 as the two solutions to the quadratic formula
## HINT2: square root is the same as taking something to the power 0.5
+
#* Exponentiation: x**y (x to the y power)
 +
#* Square root is the same as taking something to the power 0.5
 +
#* Remember to use parentheses
 +
#* Watch out for order of operations!
 
# Print the quadratic equation: a*x^2 + b*x + c = 0
 
# Print the quadratic equation: a*x^2 + b*x + c = 0
 
# Print the two real solutions of the quadratic formula
 
# Print the two real solutions of the quadratic formula
 
  
 
# CHALLENGE: check if the solutions are real or imaginary
 
# CHALLENGE: check if the solutions are real or imaginary

Revision as of 10:29, 7 October 2010

Objective:

  • You will create a program that calculates the quadratic formula from given user input

Resources:

Directions:

  1. Create a program named quad.py
  2. Prompt the user (ask the user for input) for variables a, b, and c
  3. Calculate both real solutions using the quadratic formula (look it up on the internets)
    • There are two roots to calculate
    • You should have two variables x1 and x2 as the two solutions to the quadratic formula
    • Exponentiation: x**y (x to the y power)
    • Square root is the same as taking something to the power 0.5
    • Remember to use parentheses
    • Watch out for order of operations!
  4. Print the quadratic equation: a*x^2 + b*x + c = 0
  5. Print the two real solutions of the quadratic formula
  1. CHALLENGE: check if the solutions are real or imaginary
  2. CHALLENGE2: print both solutions even if imaginary

Examples:

Please enter a: 1
Please enter b: 3
Please enter c: 2

Your equation is 1*x^2+3*x+2=0
The roots are:
-1.0
-2.0

---

Please enter a: 2
Please enter b: 3
Please enter c: 1

Your equation is 2*x^2+3*x+1=0
The roots are:
-0.5
-1.0