This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
Script version: Python 3 (may not work in Python 2) | |
This script demonstrates setting a variable to an int and to a float. | |
A float is sometimes called a "real" and an int is also known as a | |
"whole number". | |
The point of this demo: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while True: | |
# read number from user | |
# if the number is in the range to exit, then break out of this loop | |
if n >= 1 and n <= 10: | |
break |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This script is a demonstration of asking the user to enter an | |
# int in Python 3 | |
# ask the user to enter an int | |
string = input("Please enter an int: ") | |
# the function input() returns a str we need to convert it to be an int | |
n = int(string) | |
# echo the int back to the user |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
def main(): | |
# require Python 3 | |
import sys | |
if sys.version_info.major < 3: | |
print("This program requires Python 3 or later") | |
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import sys | |
print(sys.version_info) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
print(sys.version_info) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This code needs to be placed within the .bash_profile file of the user's home directory | |
# You can use a text editor such as Text Wrangler.app downloaded from the following | |
# link to create or edit the file .bash_profile, which is an invisible file because it begins | |
# with a dot. | |
# TextWrangler: http://www.barebones.com/products/textwrangler/download.html | |
# set the path to our Python Library | |
# require that '$HOME' be set to a dir | |
if [ -d "$HOME" ]; then | |
# set the path to our PYTHON_LIB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This Python source file demonstrates how Python for-loops | |
and the main() method are easier for students to understand | |
than Java is. | |
About Python: http://www.python.org/about/ | |
Free Python Download: http://www.python.org/download/ | |
It is worth considering teaching beginning students Python | |
and teach Java in more advanced courses. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.swing.JFrame; | |
import javax.swing.JLabel; | |
import javax.swing.SwingUtilities; | |
/** | |
* This class is an example of how to correctly startup a GUI interface | |
* | |
* From Oracle's Java Tutorial: | |
* http://docs.oracle.com/javase/tutorial/uiswing/concurrency/initial.html | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This class demonstrates how to write code that can process a matrix (i.e. a two-dimensional array) | |
* Note that the method printMatrix will print any two-dimensional array of ints | |
* | |
* @author kaydell | |
* | |
* Copyright, 2013, Kaydell Leavitt, All Rights Reserved | |
* | |
* {link http://simple.wikipedia.org/wiki/Matrix_%28mathematics%29} | |
* |
NewerOlder