''' Purpose: demonstrate program user communication Author: Jim Cohoon Email id: jpc ''' # triple quote = header comments # ''' everything between these are strings/comments and thus do not get evaluated; only for readers ''' # can contain many lines # usually goes at the top of the program: # contains: purpose of the program, author, contact info (your computing id); do this for your hw assignments # hashtags annotate single lined comments --> everything after is ignored # comments are ignored! # comments are helpful to describe what your code is doing but don't over comment; # Send message to program user : this describes what the print statement does; only for the user! not the program print( 'Hoos are a single community' ) # this prints whatever is inside () to the console --> generate output # print() is a built-in FUNCTION; built-in = always available # the name print() HAS TO BE LOWERCASE; NAMING AND LETTER CASE ARE IMPORTANT # built-in functions are usually all lowercase # Print( 'Hoos alive?' ) DOES NOT work; will give you error because python does not recognize it # (try uncommenting it - delete the hashtag - then run the code) # print 'Happy Hump Day' -- DOES NOT work; gives you Syntax error # () are necessary for ALL functions - this is a syntax rule --> code will not run if a syntax error occurs # errors will often tell you which line the code went wrong and what is wrong with it; look to error messages and retrace your steps # always start typing at the very left side; don't indent anything yet # identifier: sequence of characters that starts with a letter and can be followed by letters and numbers (letters include _ ) # no limit on the number of characters in the identifier # letters should all be lowercase! # identifiers are used to annotate something # style rule for identifier: # names should not start with _ unless they have special meanings; in this class, you won't use underscore to start an identifier # style rules are not strict; the code will still run, but it doesn't look pretty # statement: instruction to do something # PyCharm uses color coding to indicate code parts and comments # whitespace = blank line; used to separate important parts of the program --> makes your code more readable and cleaner # Python ignores whitespace; doesn't do anything # doesn't care; program still runs # code: a singular statement/group of statements # execute = run --> python evaluates the code you've written from top to bottom # python interprets code # makes sure code is legal, have correct syntax --> translate code from top to bottom (this will be important later) # exit code 0 --> success # if not 0 --> not successful; something failed # to run a program: also can right click here, then click Run print() # print() function does not need an argument (the thing inside parentheses) --> will print a new line in the console (the bottom screen) # print( rubber ) # will fail without quotes # can have as many print statements in a program as you want print( 'rubber' ) # will print what's exactly between the '' print( "duckies" ) # 'characters' are the same as "characters"; single quotes = double quotes # '' and "" denote strings/literals: made up of characters (letters, punctuations, symbols, numbers), appearing as exactly inside '' and "" # literal is a kind of string # spaces between things are also whitespaces; will get ignored; helps to make your code more readable # print('rubber') == print( 'rubber' ) == print( 'rubber' ) --> will only print out 'rubber' in the console # spaces inside the quotes are part of the string because a space is also a character # print( " duckies" ) --> shows " duckies" in the console # you can have comments that go after a line of code --> the rest of that line will be ignored and the code will still run # (example: lines 61, 62) # invoking/invocation: when you start a function # functions have "arguments" = the things inside () and the things you want to be displayed # print( 'duckies' ) --> 'duckies' is an argument for the print() function # print() can have multiple arguments (separated by commas), and the arguments can be of any type # can print numbers, decimals, strings # can be in any order # when elements are separated by commas, each element is separated by a space in the console when you run the program print( 1, 3.14, 'a, b, c' ) # numbers (integers, decimals) are NOT literals; they are written WITHOUT quotes --> THIS IS IMPORTANT very soon # when you run a program, it will always run the entire thing! # debug is a way you can step through each line; it helps you to find out where your code went wrong; # you won't have to do this in this class # yes, PyCharm autosaves whenever you run the program