\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{mmildmilds} \pdfinfo{ /Title (pythonn.pdf) /Creator (Cheatography) /Author (mmildmilds) /Subject (pythonn Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{D583E6} \definecolor{LightBackground}{HTML}{F9EFFB} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{pythonn Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{mmildmilds} via \textcolor{DarkBackground}{\uline{cheatography.com/25734/cs/7622/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}mmildmilds \\ \uline{cheatography.com/mmildmilds} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 23rd March, 2016.\\ Updated 12th May, 2016.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{3} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{function}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{def nameOfFunction(): \newline % Row Count 1 (+ 1) print ('This function has no parameters') \newline % Row Count 3 (+ 2) print ('This function has no return value') \newline % Row Count 5 (+ 2) return \# no value, just exits the function \newline % Row Count 6 (+ 1) \#function call \newline % Row Count 7 (+ 1) nameOfFunction() \newline % Row Count 8 (+ 1) \#function with 1 parameter/argument \newline % Row Count 9 (+ 1) def testFunction(param): \newline % Row Count 10 (+ 1) print ('This function has 1 parameter') \newline % Row Count 11 (+ 1) print (param) \newline % Row Count 12 (+ 1) \#function call \newline % Row Count 13 (+ 1) testFunction ("this is the parameter value") \newline % Row Count 14 (+ 1) \#function with 2 parameters and a return value \newline % Row Count 15 (+ 1) def function3(param1, param2): \newline % Row Count 16 (+ 1) print('This function has 2 parameters') \newline % Row Count 17 (+ 1) return param1 + param2 \# return value \newline % Row Count 18 (+ 1) \#function call and store the result in a variable \newline % Row Count 19 (+ 1) returnValue = function3(2, 3) \newline % Row Count 20 (+ 1) print (returnValue)% Row Count 21 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Countdown}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{user\_number = input("What is the number?" ) \newline % Row Count 1 (+ 1) number = int(user\_number) \newline % Row Count 2 (+ 1) countdown\_string =' ' \newline % Row Count 3 (+ 1) while number \textgreater{} 0: \newline % Row Count 4 (+ 1) countdown\_string = countdown\_string + str(number) \newline % Row Count 6 (+ 2) number = number-1 \newline % Row Count 7 (+ 1) print(countdown\_string)% Row Count 8 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Countdown}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{user\_number = input("What is the number?" ) \newline % Row Count 1 (+ 1) number = int(user\_number) \newline % Row Count 2 (+ 1) countdown\_string =' ' \newline % Row Count 3 (+ 1) while number \textgreater{} 0: \newline % Row Count 4 (+ 1) countdown\_string = countdown\_string + str(number) \newline % Row Count 6 (+ 2) number = number-1 \newline % Row Count 7 (+ 1) print(countdown\_string)% Row Count 8 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{one word per line}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{mystr = input(" Please enter your word") \newline % Row Count 1 (+ 1) letter\_num = 0 \newline % Row Count 2 (+ 1) while letter\_num \textless{} len(mystr): \newline % Row Count 3 (+ 1) print (mystr{[}letter\_num{]}) \newline % Row Count 4 (+ 1) letter\_num = letter\_num + 1% Row Count 5 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{one word per line}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{mystr = input(" Please enter your word") \newline % Row Count 1 (+ 1) letter\_num = 0 \newline % Row Count 2 (+ 1) while letter\_num \textless{} len(mystr): \newline % Row Count 3 (+ 1) print (mystr{[}letter\_num{]}) \newline % Row Count 4 (+ 1) letter\_num = letter\_num + 1% Row Count 5 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Function of name}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{mystr = "hello THERE" \newline % Row Count 1 (+ 1) print (mystr.upper()) \textgreater{} HELLO THERE \newline % Row Count 2 (+ 1) print (mystr.lower()) \textgreater{} hello there \newline % Row Count 3 (+ 1) print (mystr.capitalize()) \textgreater{} Hello there \newline % Row Count 4 (+ 1) print (mystr.title()) \textgreater{} Hello There% Row Count 5 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{asking name}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{firstname = input("What is your fisrt name?") \newline % Row Count 1 (+ 1) lastname = input("What is your last name?") \newline % Row Count 2 (+ 1) fullname = firstname + " " + lastname \newline % Row Count 3 (+ 1) print(fullname) \newline % Row Count 4 (+ 1) letternumber = input("What is the letter of number?") \newline % Row Count 6 (+ 2) letternumber = int(letternumber) \newline % Row Count 7 (+ 1) if letternumber\textgreater{}len(fullname): \newline % Row Count 8 (+ 1) print("Invalid letter number, try again") \newline % Row Count 9 (+ 1) else: \newline % Row Count 10 (+ 1) print(fullname{[}letternumber{]}) \newline % Row Count 11 (+ 1) times = input("How many times to print the letter?") \newline % Row Count 13 (+ 2) times = int(times) \newline % Row Count 14 (+ 1) if times\textgreater{}100: \newline % Row Count 15 (+ 1) print("Too many letters to print") \newline % Row Count 16 (+ 1) else: \newline % Row Count 17 (+ 1) print(fullname{[}letternumber{]}*times) \newline % Row Count 18 (+ 1) Result \newline % Row Count 19 (+ 1) What is your fisrt name? Pear \newline % Row Count 20 (+ 1) What is your last name? Tan \newline % Row Count 21 (+ 1) Pear Tan \newline % Row Count 22 (+ 1) What is the letter of number? 4 \newline % Row Count 23 (+ 1) r \newline % Row Count 24 (+ 1) How many times to print the letter? 12 \newline % Row Count 25 (+ 1) rrrrrrrrrrrr% Row Count 26 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{List}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{myself= "hello123" \newline % Row Count 1 (+ 1) numbers = {[}1,2,3,4,5,6{]} \newline % Row Count 2 (+ 1) print(numbers) \newline % Row Count 3 (+ 1) shoppinglist = {[}'shoe','bags','pants','shirt'{]} \newline % Row Count 4 (+ 1) print(shoppinglist) \newline % Row Count 5 (+ 1) mixed={[}1,'Hello',2.5, True, False{]} \newline % Row Count 6 (+ 1) print(mixed) \newline % Row Count 7 (+ 1) letter\_num = 0 \newline % Row Count 8 (+ 1) while letter\_num \textless{} len(mystr): \newline % Row Count 9 (+ 1) print (mystr{[}letter\_num{]}) \newline % Row Count 10 (+ 1) letter\_num = letter\_num + 1 \newline % Row Count 11 (+ 1) for myletterisawesome in mystr: \newline % Row Count 12 (+ 1) print(myletterisawesome) \newline % Row Count 13 (+ 1) for tientien in shoppinglist: \newline % Row Count 14 (+ 1) print(opal) \newline % Row Count 15 (+ 1) shoppinglist. append('ties') \newline % Row Count 16 (+ 1) print(shoppinglist) \newline % Row Count 17 (+ 1) out = 0 \newline % Row Count 18 (+ 1) for mrtim in shoppinglist: \newline % Row Count 19 (+ 1) out=out + 1 \newline % Row Count 20 (+ 1) print(mrtim) \newline % Row Count 21 (+ 1) print (out) \newline % Row Count 22 (+ 1) largelist = range(100) \newline % Row Count 23 (+ 1) for num in largelist: \newline % Row Count 24 (+ 1) print(num)% Row Count 25 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Symbol n vocab}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{variable-A value or thing that can be changed \newline % Row Count 1 (+ 1) string-A list of character such as letter or symbol \newline % Row Count 3 (+ 2) modulo-Find the remainder \newline % Row Count 4 (+ 1) **-exponent \newline % Row Count 5 (+ 1) /-divide and quotient (result) is float \newline % Row Count 6 (+ 1) //-divide and quotient (result) is integer \newline % Row Count 7 (+ 1) != - not equal to \newline % Row Count 8 (+ 1) \textless{}= - less than or eqaul to \newline % Row Count 9 (+ 1) \textgreater{}= - more than or equal to \newline % Row Count 10 (+ 1) True or anything \newline % Row Count 11 (+ 1) Always true \newline % Row Count 12 (+ 1) False and anything \newline % Row Count 13 (+ 1) False% Row Count 14 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{for loop print 0 01 012 0123 01234}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{mystring = "" \newline % Row Count 1 (+ 1) for num in range(5): \newline % Row Count 2 (+ 1) mystring = mystring + str(num) \newline % Row Count 3 (+ 1) print (mystering)% Row Count 4 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{print thing in list while loop}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{my list = {[}1,2,3,4,5{]} \newline % Row Count 1 (+ 1) num = 0 \newline % Row Count 2 (+ 1) while num\textless{}len(my list): \newline % Row Count 3 (+ 1) print(mylist{[}num{]}) \newline % Row Count 4 (+ 1) num=num+1% Row Count 5 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{convert binary}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{user\_number = input("Please enter a number") \newline % Row Count 1 (+ 1) number = int(user\_number) \newline % Row Count 2 (+ 1) binary\_string ='' \newline % Row Count 3 (+ 1) while (number \textgreater{} 0): \newline % Row Count 4 (+ 1) remainder= number\%2 \newline % Row Count 5 (+ 1) binary\_string = str(remainder) + binary\_string \newline % Row Count 7 (+ 2) number= number//2 \newline % Row Count 8 (+ 1) print("Binary string is", binary\_string) \newline % Row Count 9 (+ 1) Result \newline % Row Count 10 (+ 1) Please enter a number 36 \newline % Row Count 11 (+ 1) Binary string is 100100% Row Count 12 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{range}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\#creates a list of numbers from 0 to the specified \newline % Row Count 2 (+ 2) number \newline % Row Count 3 (+ 1) numberlist = range(5) \newline % Row Count 4 (+ 1) \# is the same as creating the following list \newline % Row Count 5 (+ 1) numberlist2 = {[}0, 1, 2, 3, 4{]} \newline % Row Count 6 (+ 1) for num in range(100): \newline % Row Count 7 (+ 1) print (num) \# prints all numbers from 0 – 99 \newline % Row Count 9 (+ 2) for num in range(5, 50): \newline % Row Count 10 (+ 1) print(num) \#prints all numbers from 5 - 49% Row Count 11 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{palindrome}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{def palindrome(word): \newline % Row Count 1 (+ 1) letter\_num = 0 \newline % Row Count 2 (+ 1) reverse = "" \newline % Row Count 3 (+ 1) for letter\_num in word: \newline % Row Count 4 (+ 1) reverse = letter\_num + reverse \newline % Row Count 5 (+ 1) if word == reverse: \newline % Row Count 6 (+ 1) return True \newline % Row Count 7 (+ 1) else: \newline % Row Count 8 (+ 1) return False \newline % Row Count 9 (+ 1) while True: \newline % Row Count 10 (+ 1) user\_word = input("Please enter a word: ") \newline % Row Count 11 (+ 1) if user\_word != "quit": \newline % Row Count 12 (+ 1) print("This word has",len(user\_word),"letters") \newline % Row Count 14 (+ 2) if user\_word == "quit": \newline % Row Count 15 (+ 1) break \newline % Row Count 16 (+ 1) if palindrome(user\_word) == True: \newline % Row Count 17 (+ 1) print(user\_word,"is palindrome") \newline % Row Count 18 (+ 1) else: \newline % Row Count 19 (+ 1) print(user\_word,"is not palindrome")% Row Count 20 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{0 01 012 0123 01234}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{expected out put \newline % Row Count 1 (+ 1) 0 01 012 0123 01234 \newline % Row Count 2 (+ 1) mystring = "" \newline % Row Count 3 (+ 1) count = 0 \newline % Row Count 4 (+ 1) while count\textless{}5: \newline % Row Count 5 (+ 1) mystring = mystring+str(count) \newline % Row Count 6 (+ 1) print(mystring) \newline % Row Count 7 (+ 1) count = count+1% Row Count 8 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{function multiplication table 5'1-5 5'2-10}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{def muHiplicationTable(): \newline % Row Count 1 (+ 1) user\_input = input("enter a number:") \newline % Row Count 2 (+ 1) num = int(user\_input) \newline % Row Count 3 (+ 1) count = 1 \newline % Row Count 4 (+ 1) while count \textless{}=10: \newline % Row Count 5 (+ 1) print(num,"{\emph{",count,"=",num}}count) \newline % Row Count 6 (+ 1) count = count + 1% Row Count 7 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{what is the output of the following code}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{x = false \newline % Row Count 1 (+ 1) print (x and True or 1 == 1 \newline % Row Count 2 (+ 1) ans- true \newline % Row Count 3 (+ 1) y = true \newline % Row Count 4 (+ 1) print (not y or 2\textless{}3) \newline % Row Count 5 (+ 1) and-true% Row Count 6 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{area of triangle and prism}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{def areaOfTriangle(b,h): \newline % Row Count 1 (+ 1) if user\_base\textless{}=0: \newline % Row Count 2 (+ 1) return "Error: invalid radius" \newline % Row Count 3 (+ 1) if user\_height\textless{}=0: \newline % Row Count 4 (+ 1) return "Error: invalid radius" \newline % Row Count 5 (+ 1) area = 0.5 b h \newline % Row Count 6 (+ 1) return area \newline % Row Count 7 (+ 1) user\_base =float(input('Enter the base of the triangle:')) \newline % Row Count 9 (+ 2) user\_height = float(input('Enter the height of the triangle: ')) \newline % Row Count 11 (+ 2) print ('The area of the triangle is',areaOfTriangle(user\_base,user\_height)) \newline % Row Count 13 (+ 2) def volumeOfPrism(b,h,l): \newline % Row Count 14 (+ 1) volume = bhl \newline % Row Count 15 (+ 1) return volume \newline % Row Count 16 (+ 1) user\_length = float(input('Enter the length of the prism:')) \newline % Row Count 18 (+ 2) print('The volume of the prism is', volumeOfPrism(user\_base,user\_height,user\_length))% Row Count 20 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{area of circle}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{def areaOfCircle (user\_radius): \newline % Row Count 1 (+ 1) if user\_radius\textless{}=0: \newline % Row Count 2 (+ 1) return "Error: invalid radius" \newline % Row Count 3 (+ 1) pi = 3.1415 \newline % Row Count 4 (+ 1) area = pi{\emph{(user\_radius}}*2) \newline % Row Count 5 (+ 1) return area \newline % Row Count 6 (+ 1) user\_radius = float(input("Enter the radius: ")) \newline % Row Count 7 (+ 1) print('The area of the circle is', \seqsplit{areaOfCircle(user\_radius)}% Row Count 9 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Rules of naming var}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\# letters \newline % Row Count 1 (+ 1) \# numbers \newline % Row Count 2 (+ 1) \# underscore (\_) \newline % Row Count 3 (+ 1) \# can either start with letter or underscores ONLY \newline % Row Count 5 (+ 2) \# no space \newline % Row Count 6 (+ 1) Example \newline % Row Count 7 (+ 1) Hello\_there \newline % Row Count 8 (+ 1) me2 \newline % Row Count 9 (+ 1) \_mynumber \newline % Row Count 10 (+ 1) Invalid names \newline % Row Count 11 (+ 1) \# 3my =cannot start with number \newline % Row Count 12 (+ 1) \# last name = no spaces allowed \newline % Row Count 13 (+ 1) \# last-name = dashes are not accepted% Row Count 14 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{multiplication}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{string {\emph{ number - Repeat those thing for the number of time \newline string }} string - Crash! \newline number {\emph{ number - Multiply like in math \newline string {\bf{ number - Crash! \newline number }} number - Exponent in Math \newline number }}* string - Crash! \newline sring + string - combine those strings together \newline string + number - program will be crash} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{print all even num 1-100 while loop}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{num = 0 \newline % Row Count 1 (+ 1) while num\textless{}100 \newline % Row Count 2 (+ 1) num=num+2 \newline % Row Count 3 (+ 1) print(num)% Row Count 4 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{fibonacci from 0-50}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{num1 = 0 \newline % Row Count 1 (+ 1) num2 = 0 \newline % Row Count 2 (+ 1) fibonacci = num1+num2 \newline % Row Count 3 (+ 1) myoutput = "0,1" \newline % Row Count 4 (+ 1) while fibonacci \textless{} 50: \newline % Row Count 5 (+ 1) myoutput = myouput + "," + str(fibonacci) \newline % Row Count 7 (+ 2) num1=num2 \newline % Row Count 8 (+ 1) num2 = fibonacci \newline % Row Count 9 (+ 1) fibonacci = num1+ num2 \newline % Row Count 10 (+ 1) print(my output) \newline % Row Count 11 (+ 1) 0,1,1,2,3,5,8,13,...% Row Count 12 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{ask user and is num divisible by3}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{num = int(input(input("enter a number")) \newline % Row Count 1 (+ 1) remainder = num \% 3 \newline % Row Count 2 (+ 1) if remainder == 0: \newline % Row Count 3 (+ 1) print (num, "is divisible by 3") \newline % Row Count 4 (+ 1) else: \newline % Row Count 5 (+ 1) print (num, "isn't divisible by 3")% Row Count 6 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{ยากๆอะ}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{write a program that repeatly receive positive int from user enters a negative integer exit the loop print how many of numbers entered were even and odd \newline % Row Count 4 (+ 4) evencount=0 \newline % Row Count 5 (+ 1) oddcount=0 \newline % Row Count 6 (+ 1) while True: \newline % Row Count 7 (+ 1) num = int(input("enter a positive integer")) \newline % Row Count 8 (+ 1) if num\textless{}0: \newline % Row Count 9 (+ 1) print("even number:",evencount) \newline % Row Count 10 (+ 1) print("odd numbers:",oddCOunt) \newline % Row Count 11 (+ 1) break \newline % Row Count 12 (+ 1) else: \newline % Row Count 13 (+ 1) if(num\%2)==0 \newline % Row Count 14 (+ 1) evencount - evencount+1 \newline % Row Count 15 (+ 1) else: \newline % Row Count 16 (+ 1) oddcount = oddcount + 1% Row Count 17 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Reverse}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{word = input("Please enter a word to reverse: ") \newline % Row Count 1 (+ 1) letter\_num = 0 \newline % Row Count 2 (+ 1) reverse = "" \newline % Row Count 3 (+ 1) while letter\_num \textless{}len(word): \newline % Row Count 4 (+ 1) reverse = word{[}letter\_num{]} + reverse \newline % Row Count 5 (+ 1) letter\_num = letter\_num + 1 \newline % Row Count 6 (+ 1) print("Reverse: ",reverse)% Row Count 7 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{guess game}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{import random \newline % Row Count 1 (+ 1) mylist = {[}'lion','cheetah','panther','cougar','leopard'{]} \newline % Row Count 3 (+ 2) random\_item = random.choice(mylist) \newline % Row Count 4 (+ 1) print(random\_item) \newline % Row Count 5 (+ 1) print(mylist{[}0{]}) \newline % Row Count 6 (+ 1) user\_guess = input("Guess a word: ") \newline % Row Count 7 (+ 1) if user\_guess == random\_item: \newline % Row Count 8 (+ 1) print("Correct") \newline % Row Count 9 (+ 1) else: \newline % Row Count 10 (+ 1) if user\_guess in mylist: \newline % Row Count 11 (+ 1) print("Yes, it is in the list") \newline % Row Count 12 (+ 1) else: \newline % Row Count 13 (+ 1) print("No, it is not in the list")% Row Count 14 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{guess game}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{import random \newline % Row Count 1 (+ 1) mylist = {[}'lion','cheetah','panther','cougar','leopard'{]} \newline % Row Count 3 (+ 2) random\_item = random.choice(mylist) \newline % Row Count 4 (+ 1) print(random\_item) \newline % Row Count 5 (+ 1) print(mylist{[}0{]}) \newline % Row Count 6 (+ 1) user\_guess = input("Guess a word: ") \newline % Row Count 7 (+ 1) if user\_guess == random\_item: \newline % Row Count 8 (+ 1) print("Correct") \newline % Row Count 9 (+ 1) else: \newline % Row Count 10 (+ 1) if user\_guess in mylist: \newline % Row Count 11 (+ 1) print("Yes, it is in the list") \newline % Row Count 12 (+ 1) else: \newline % Row Count 13 (+ 1) print("No, it is not in the list")% Row Count 14 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{def of word}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{def printDefinition(word): \newline % Row Count 1 (+ 1) \# write a definition in your own words for the folllowing words: \newline % Row Count 3 (+ 2) \# use multi-line strings to print the definition \newline % Row Count 5 (+ 2) \#variable \newline % Row Count 6 (+ 1) if word == "variable": \newline % Row Count 7 (+ 1) print("""A variable is thing that can be changed""") \newline % Row Count 9 (+ 2) elif word == "function": \newline % Row Count 10 (+ 1) \#function \newline % Row Count 11 (+ 1) print (""" A function is a thing that reuse block or quote. """) \newline % Row Count 13 (+ 2) elif word == "parameter": \newline % Row Count 14 (+ 1) \#parameter \newline % Row Count 15 (+ 1) print("""A parameter is thing inside blacket of function """) \newline % Row Count 17 (+ 2) elif word == "agument": \newline % Row Count 18 (+ 1) \#argument \newline % Row Count 19 (+ 1) print(""" A argument is the same thing as parameter. It is thinfg inside blacket f function """) \newline % Row Count 22 (+ 3) elif word == "function call": \newline % Row Count 23 (+ 1) \#function call \newline % Row Count 24 (+ 1) print("""Function is the thing make fuction run.""") \newline % Row Count 26 (+ 2) elif word == "string": \newline % Row Count 27 (+ 1) \#string \newline % Row Count 28 (+ 1) print(""" A string is a list of character""") \newline % Row Count 30 (+ 2) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{def of word (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{ else: \newline % Row Count 1 (+ 1) print("unknown word") \newline % Row Count 2 (+ 1) while True: \newline % Row Count 3 (+ 1) word = input ("Enter the word") \newline % Row Count 4 (+ 1) printDefinition(word) \newline % Row Count 5 (+ 1) Result \newline % Row Count 6 (+ 1) Enter the wordvariable \newline % Row Count 7 (+ 1) A variable is thing that can be changed \newline % Row Count 8 (+ 1) Enter the wordfunction \newline % Row Count 9 (+ 1) A function is a thing that reuse block or quote. \newline % Row Count 11 (+ 2) Enter the wordagument \newline % Row Count 12 (+ 1) A argument is the same thing as parameter. It is thinfg inside blacket f function \newline % Row Count 14 (+ 2) Enter the wordfunction call \newline % Row Count 15 (+ 1) Function is the thing make fuction run. \newline % Row Count 16 (+ 1) Enter the wordstring \newline % Row Count 17 (+ 1) A string is a list of character \newline % Row Count 18 (+ 1) Enter the wordpear \newline % Row Count 19 (+ 1) unknown word% Row Count 20 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}