Haverford Cascade Mentoring Program - PowerPoint PPT Presentation

1 / 21
About This Presentation
Title:

Haverford Cascade Mentoring Program

Description:

programming language, both C and C are widely used ... Python is a portable, interpreted, object-oriented programming language. ... – PowerPoint PPT presentation

Number of Views:114
Avg rating:3.0/5.0
Slides: 22
Provided by: haver
Category:

less

Transcript and Presenter's Notes

Title: Haverford Cascade Mentoring Program


1
Haverford Cascade Mentoring Program
  • Computer Programming
  • C to Python Conversion
  • Professor Dave Wannacott
  • Student Kris Brower
  • Dobbins Vocational Tech
  • Teacher Andre OBrien
  • Student Denisha Davis

2
C and Python
  • Brief History C
  •     In 1985 Bjarne Stroustrup, also of Bell
    Labs,invented the C programming language. To
    the Clanguage he added features for data
    abstraction andobject-oriented programming.
    Instead of naming thelanguage D, the Bell Labs
    group named it C in ahumorous vein. As we see
    later, signifies theincrement operation  in
    the C and C language. Givena variable x, the
    expression x means to increment(add one to)
    the current value of x. Therefore, thename C
    suggests an enhanced ("incremented") versionof
    the C language. Although C originally was
    intended as a systemprogramming language, both C
    and C are widely usedtoday in business,
    industry, and personal computing.C is powerful
    and versatile, embodying a wide rangeof
    programming concepts.

3
C and Python
  • Brief History Python
  • Python is a portable, interpreted,
    object-oriented programming language. Its
    development started in 1990 at CWI in Amsterdam,
    and continues under the ownership of the Python
    Software Foundation. The language has an elegant
    (but not over-simplified) syntax a small number
    of powerful high-level data types are built in.
    Python can be extended in a systematic fashion by
    adding new modules implemented in a compiled
    language such as C or C. Such extension modules
    can define new functions and variables as well as
    new object types.

4
Differences Between C and Python
  • Simple program
  • Comments (Declarations)
  • Syntax (input/output)
  • Variables (Identifier and Data Type)
  • If statement
  • While loops
  • For loops
  • Functions

5
Simple program
  • C
  • include ltiostream.hgt
  • int main()
  • coutltltHello Haverfordltltendl
  • return 0
  • Python
  • print Hello Haverford

6
Simple program (with comments)
  • C
  • //this program demonstrates C
  • //in its simplest form
  • include ltiostream.hgt
  • int main()
  • coutltltHello Haverfordltltendl
  • return 0
  • Python
  • this program demonstrates
  • python in its simplest form
  • print Hello Haverford

7
Syntax (input/output)
  • C
  • coutltltPlease enter a name ltltendl
  • cingtgtname
  • coutltltthe name you entered was, nameltltendl
  • Python
  • name raw_input(Please enter a name)
  • print the name you entered was, name

8
Variables
  • C
  • int number
  • char name
  • float calculate
  • number 27
  • name Denisha
  • calculate 99.8
  • Python
  • Number 27
  • Name Denisha
  • Calculate 99.8

9
If statement (If-Then-Else form)
  • C
  • Num1 10
  • Num2 32
  • Num3 14
  • If (num1 gt num2)
  • coutltlt10 is greater than 32ltltendl
  • Else if (num2 lt num3)
  • coutltlt32 is less than 14ltltendl
  • Else if (num3 gt num2)
  • coutltlt14 is greater than 32ltltendl
  • Else
  • Python
  • Num1 10
  • Num2 32
  • Num3 14
  • If num1 gt num2
  • print 10 is greater than 32
  • Elif num2 lt num3
  • print 32 is less than 14
  • Elif num3 gtnum2
  • print 14 is greater than 32
  • Else
  • print please review your first grade math
    material

10
While loops
  • C
  • Count 0
  • While (count lt 10)
  • coutltltAndre OBrienltltendl
  • count count 1
  • Python
  • Count 0
  • While count lt 10
  • print Andre OBrien
  • count count 1

11
For loops
  • C
  • For (loopCount 1 loopCountlt10 loopCount)
  • coutltltAndre OBrienltltendl
  • Python
  • For loopCount in range(10)
  • print Andre OBrien

12
Functions
  • C
  • Void someFunction()
  • count 0
  • while (countlt10)
  • coutltltHey OBltltendl
  • someFunction() //function call
  • Python
  • Def someFunction
  • count 0
  • while count lt 10
  • print Hey OB
  • someFunction() function call

13
Differences Between C and Python Summary
  • On the average Python programs compile slower
    than C programs. However, it usually takes
    less time to write programs in Python and they
    tend to be shorter in length than their C
    counter parts. The approach to programming
    remains virtually the same.
  • Another noteworthy comparison deals with how
    C and Python deals with debugging issues. C
    highlights a syntax or logic error but you must
    know the language well to understand whats
    wrong. Python, on the other hand, doesnt
    highlight your errors. It does, however, tell
    you what line your error can be found on and it
    tells you what datatype or function is undefined.
    I personally prefer Pythons approach better.

14
Summer Experiment Lab 1
  • Do two lines overlap?
  • Do two rectangles overlap?
  • Do two circles overlap?
  • Does a rectangle and a circle overlap?
  • Do two line segments intersect? beyond the
    scope of my current skill level.

15
Lab 1
16
Do two lines overlap?
  • Level beginner
  • Do 2 ranges overlap?
  • def range_overlap(min1,max1,min2,max2)
  • if max1 lt min2 or min1 gt max2
  • return False
  • else
  • return True

17
Do two rectangles overlap?
  • Level beginner
  • Do 2 Windows overlap?
  • Def window_overlap(minx1,maxx1,miny1

  • ,maxy1,minx2,maxx2,miny2,maxy2)
  • if maxy1ltminy2 or maxx1ltminx2 or maxy2 lt
    miny1 or
  • maxx2 lt minx1
  • return False
  • else
  • return True

18
Do two circles overlap?
  • Level intermediate
  • Do 2 Cicles overlap?
  • def circle_overlap(x1,y1,r1,x2,y2,r2)
  • distanceX x2 - x1
  • distanceY y2 - y1
  • distanceGAP pow(distanceX,2)
    pow(distanceY,2)
  • roc r1 r2
  • roc pow(roc,2)
  • if distanceGAPltroc
  • return True
  • else
  • return False

19
Does a rectangle and a circle overlap?
  • Level hard
  • Do a circle and a rectangle overlap?
  • def circle_rectangle_overlap(center_x,center_y,

  • radius,xmin,xmax,ymin,ymax)
  • testX center_x
  • testY center_y
  • if testX lt xmin
  • testX xmin
  • if testX gt xmax
  • testX xmax
  • if testY lt ymin
  • testY ymin
  • if testY gt ymax
  • testY ymax
  • distanceX2 (center_x-testX)
    (center_x-testX)

20
Do two line segments intersect?
  • Level down right unfair!

21
Conclusion
  • C and Python
  • Out with the Old in with the New!!!
Write a Comment
User Comments (0)
About PowerShow.com