Created
June 30, 2020 04:41
-
-
Save peterdcasey/bbb92756c98e46da54cfd4be56d06c54 to your computer and use it in GitHub Desktop.
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
""" | |
Sample Python Code | |
""" | |
def sample_one(): | |
''' | |
Input two numbers | |
Print the result of the product | |
''' | |
x = int(input("Number? ")) | |
y = int(input("Number? ")) | |
print("Result of", x, "*", y, "is", x * y) | |
# Ouput a blank line | |
print() | |
def basic_ideas(): | |
''' | |
Demonstrate a few basic Python concepts | |
with print() and assignments. | |
''' | |
# Output the literal string 'hello world' | |
print("hello world") | |
# Output string, string, int, float | |
print("cat", "dog", 10, 3432.444) | |
# Assign the label 'x' to the int object 100 | |
x = 100 | |
# Assign the label 'y' to the int object 100 (two labels now on 100) | |
y = x | |
# Assign the label 'name' to the string object 'Bob' | |
name = "Bob" | |
# Assign the label 'x' to the int object 200 (removed from 100) | |
x = 200 | |
# Assign the label 'y' to the object that label 'x' is on | |
y = x | |
# Assign the label 'y' to the int object 1000 | |
y = 1000 | |
# Output the values of the objects with the three labels | |
print(x, y, name) | |
# Assign the label 'y' to the int object 0, the int object 1000 is discarded | |
y = 0 | |
def main(): | |
''' | |
The main function of the program, the 'front door'. | |
Call the two functions that comprise the application. | |
''' | |
# Call the function object with the label 'sample_one' | |
sample_one() | |
# Call the function object with the label 'basic_ideas' | |
basic_ideas() | |
# Test to see if this is the main module of the application | |
if __name__ == '__main__': | |
# Call the function object with the label 'main' | |
main() | |
''' | |
Number? 45 | |
Number? 3542 | |
Result of 45 * 3542 is 159390 | |
hello world | |
cat dog 10 3432.444 | |
200 1000 Bob | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment