Presentation is loading. Please wait.

Presentation is loading. Please wait.

(Monty) Python for loops Mr. Neat. Comparison JavaC++Python source code name.java.cpp.py Object Oriented? required optional functions/ methods ( bob.hide()

Similar presentations


Presentation on theme: "(Monty) Python for loops Mr. Neat. Comparison JavaC++Python source code name.java.cpp.py Object Oriented? required optional functions/ methods ( bob.hide()"— Presentation transcript:

1 (Monty) Python for loops Mr. Neat

2 Comparison JavaC++Python source code name.java.cpp.py Object Oriented? required optional functions/ methods ( bob.hide() ) functions ( gotoxy(4,3) ) functions ( str(5) ) output new Text(“ “,,, ) System.out.print() cout << print(“ blah, blah”) input skipped this (complicated) cin>> input( ) casting int( ) int(double) int(string) if - else if(boolean) { } else { } brackets replaced by indenting! if(boolean) { } else { }

3 Strings Again Python considers a string as a collection of characters. There is a Python function that determines the number of characters in a string…. len(put string in here)

4 Comparison JavaC++Python for loops for( int i=0 ;i<10 ; i++) exact same as Java different

5 Strings again >>> temp = “surfer dude” >>> print(len(temp))

6 Strings again surfer dude 1 2 3 4 5 6 7 8 9 1011 answer

7 for loops in Python Same idea as C++ and Java – provides a mechanism for repeated actions Syntax different from C++ and Java Requires a list We are using a list of numbers via the range() function

8 range function range(num1, num2) creates the list of numbers from num1 (and including it) to num2 (but not including it) incremented by ones For example, range(0,4) produces the list 0,1,2,3

9 for loops in Python >>> for x in range(0,4): print(x) How would we list the numbers 0 through 3? 01230123

10 for loops in Python - explanation for each number in the list, write the number to the screen

11 More on print() function print(“*”) output: *

12 More on print() function print(“*”,end=‘ ‘) print(“*”) output: **

13 Lab 8 Write an app that draws a line. Ask the user for line length and if they want a horizontal or vertical line. Example output: Please enter line length: 4 Do you want a horizontal or vertical line? vertical *


Download ppt "(Monty) Python for loops Mr. Neat. Comparison JavaC++Python source code name.java.cpp.py Object Oriented? required optional functions/ methods ( bob.hide()"

Similar presentations


Ads by Google