\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{pinpin} \pdfinfo{ /Title (python.pdf) /Creator (Cheatography) /Author (pinpin) /Subject (Python 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}{FFBDDC} \definecolor{LightBackground}{HTML}{FFEEF6} \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{Python Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{pinpin} via \textcolor{DarkBackground}{\uline{cheatography.com/25830/cs/6963/}}} \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}pinpin \\ \uline{cheatography.com/pinpin} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 11th February, 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}{p{0.4977 cm} x{4.4793 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Math of Symbols}} \tn % Row 0 \SetRowColor{LightBackground} == & Equal to \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} != & No equal to \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \textless{} & Less than \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \textgreater{} & More than \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \textless{}= & Less than or equal to \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \textgreater{}= & More than or equal to \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} \% & Modulo, find the remainder \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} + & Add \tn % Row Count 8 (+ 1) % Row 8 \SetRowColor{LightBackground} - & Subtract \tn % Row Count 9 (+ 1) % Row 9 \SetRowColor{white} * & Multiplication \tn % Row Count 10 (+ 1) % Row 10 \SetRowColor{LightBackground} ** & Exponent \tn % Row Count 11 (+ 1) % Row 11 \SetRowColor{white} / & Divide and quotient is float \tn % Row Count 12 (+ 1) % Row 12 \SetRowColor{LightBackground} // & Divide and quotient is integer \tn % Row Count 13 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.93643 cm} x{2.04057 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Text}} \tn % Row 0 \SetRowColor{LightBackground} single quoted & 'example' \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} double quoted & "example" \tn % Row Count 2 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{0.84609 cm} x{4.13091 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Functions}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{print()} & display information on the screen \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{input()} & display information from the user \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} int() & convert a value to an integer \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} len() & The length of the string \tn % Row Count 6 (+ 1) % Row 4 \SetRowColor{LightBackground} \seqsplit{float()} & Change number to be decimal number \tn % Row Count 8 (+ 2) % Row 5 \SetRowColor{white} str() & converts the value to a string \tn % Row Count 9 (+ 1) % Row 6 \SetRowColor{LightBackground} \# & Comment, no effect \tn % Row Count 10 (+ 1) \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's is your name? code}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{mystring = "hello" \newline print (mystring) \newline firstname = input( "what is your first name?") \newline lastname = input( "what is your last name?") \newline fullname = firstname + " " + lastname \newline print (fullname) \newline \newline letternumber = int(input( " what is letter number? " )) \newline if letternumber \textgreater{}len(fullname): \newline print ( " invalid letter number, try again! " ) \newline else: \newline \newline letter = ( fullname{[}letternumber{]} ) \newline print (letter) \newline \newline numberletter = int(input( "how many times to print letter " )) \newline \newline if numberletter \textgreater{}100: \newline print ( " too many letters to print! " ) \newline else: \newline print (letter * numberletter )} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{hello \newline what is your first name? \newline what is your last name? \newline \newline what is letter number? \newline \newline how many times to print letter} \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 Random}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{import random \newline intlist = {[}1,10,100{]} \newline random\_int = random.choice(intlist) \newline print(random\_int,intlist) \newline \newline fplist = {[}2,20,200{]} \newline ramdom\_fp = random.choice(fplist) \newline print(ramdom\_fp,fplist) \newline \newline strlist = ('Pin','Anpan','Bella') \newline ramdom\_str = random.choice(strlist) \newline print(ramdom\_str,strlist) \newline \newline mylist = {[}1,10,100,2,20,200,'Pin','Anpan','Bella'{]} \newline ramdom\_item = random.choice(mylist) \newline print(ramdom\_item,mylist) \newline \newline myvar1 = 1 \newline myvar2 = 2 \newline myvar3 = 3 \newline varlist = {[}myvar1,myvar2,myvar3{]} \newline random\_var = random.choice(varlist) \newline print(random\_var,varlist)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{10 {[}1, 10, 100{]} \newline 200 {[}2, 20, 200{]} \newline Bella ('Pin', 'Anpan', 'Bella') \newline 2 {[}1, 10, 100, 2, 20, 200, 'Pin', 'Anpan', 'Bella'{]} \newline 3 {[}1, 2, 3{]}} \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}{bacon()}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{def bacon(): \newline print("hello it's bacon") \newline print("line 2") \newline print("line 3") \newline print("line 4") \newline return \newline bacon() \newline bacon() \newline bacon()} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{hello it's bacon \newline line 2 \newline line 3 \newline line 4 \newline hello it's bacon \newline line 2 \newline line 3 \newline line 4 \newline hello it's bacon \newline line 2 \newline line 3 \newline line 4} \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}{myprintnew (text, decoration)}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{def myprintnew (text, decoration): \newline print(decoration + str(text) + decoration) \newline return \newline myprintnew(1, "+++") \newline myprintnew('hello','-=-=-=-=-=-=-=-=') \newline myprintnew(1, "@@@@@@@")} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{+++1+++ \newline -=-=-=-=-=-=-=-=hello-=-=-=-=-=-=-=-= \newline @@@@@@@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 a triangle}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{def areaofTriangle(b, h): \newline area = 0.5 {\emph{ b }} h \newline return area \newline user\_base = float(input('Enter the base of the triangle:')) \newline user\_height = float(input('Enter the height of the triangle:')) \newline print('The area of the triangle is',areaofTriangle(user\_base, user\_height)) \newline \newline def volumeofPrism(b,h,l): \newline volume = areaofTriangle(b, h) *l \newline return volume \newline user\_lenght = float(input('Enter the length of the prism: ')) \newline print('The volume of the prism is',volumeofPrism(user\_base, user\_height, user\_lenght) )} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Enter the base of the triangle:11111 \newline Enter the height of the triangle:2222 \newline The area of the triangle is 12344321.0 \newline Enter the length of the prism: 3333 \newline The volume of the prism is 41143621893.0} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.29402 cm} x{3.68298 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Vocabulary}} \tn % Row 0 \SetRowColor{LightBackground} Variable & Hold a value and can be changed \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} String & A list of characters such as number, letters, symbols \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} Integer number & Whole number/ counting number \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} Float number & The number in decimal \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} Syntax & Grammar / Structure of language \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} Modulo & Find the remainder \tn % Row Count 11 (+ 1) % Row 6 \SetRowColor{LightBackground} Boolean & True / False \tn % Row Count 12 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Naming Conventions}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Rules for naming variables: \newline % Row Count 1 (+ 1) - letters \newline % Row Count 2 (+ 1) - numbers \newline % Row Count 3 (+ 1) - underscores (\_) \newline % Row Count 4 (+ 1) - can start with letters or underscores ONLY \newline % Row Count 6 (+ 2) - NO SPACES \newline % Row Count 7 (+ 1) Valid names: \newline % Row Count 8 (+ 1) - \_mystr \newline % Row Count 9 (+ 1) - my3 \newline % Row Count 10 (+ 1) Hello\_there \newline % Row Count 11 (+ 1) Invalid names: \newline % Row Count 12 (+ 1) - 3my= "hi" -{}- cannot start with number \newline % Row Count 13 (+ 1) - first name = "hi" -{}- no spaces allowed \newline % Row Count 14 (+ 1) - first-name -{}- dashes are not accepted% Row Count 15 (+ 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}{Example}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Print (2) – integer \newline Print (2.5) – floating point \newline Print ("Hello") – string \newline Print (mystr) – variable \newline Print (mystr,"Hi",2,1.0) -{}- commas \newline \newline mystr = "Hi" \newline mystr ← name \newline "Hi" ← value can change \newline \newline print (int(1.5)) → 1 \newline print (int("2")) → 2 \newline print (float(1)) → 1.0 anything to a float \newline \newline Modulo/Remainder \% \newline print (4\%2) → 0 \newline print (30\%7) → 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}{A radius of a circle code}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\#Ask the user for a radius of a circle \newline % Row Count 1 (+ 1) user\_radius =input("What is the radius of the circle?") \newline % Row Count 3 (+ 2) \#Convert the given radius to a floating point \newline % Row Count 4 (+ 1) radius = float(user\_radius) \newline % Row Count 5 (+ 1) \#make a variable called pi \newline % Row Count 6 (+ 1) pi = 3.1415 \newline % Row Count 7 (+ 1) \#Calculate the area of the circle using exponents \newline % Row Count 8 (+ 1) area = pi{\emph{radius}}*2 \newline % Row Count 9 (+ 1) \#display the area of the circle to the user \newline % Row Count 10 (+ 1) print("The area of the circle is" ,area)% Row Count 11 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{What is the radius of the circle?123 \newline The area of the circle is 47527.753500000006} \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 Code}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{word =input("Please enter your name: ") \newline % Row Count 1 (+ 1) index = 0 \newline % Row Count 2 (+ 1) reverse ='' \newline % Row Count 3 (+ 1) while index \textless{} len(word): \newline % Row Count 4 (+ 1) reverse = word{[}index{]}+ reverse \newline % Row Count 5 (+ 1) index = index + 1 \newline % Row Count 6 (+ 1) print ("Reverse: ",reverse)% Row Count 7 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Please enter your name: Timmy \newline Reverse: ymmiT} \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}{myprint(text)}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{def myprint(text): \newline print("{\bf{{\emph{" + str(text) + "}}}}") \newline return \newline myprint(1) \newline myprint("hello") \newline myprint(2.5)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{{\emph{1}}}} \newline {\bf{{\emph{hello}}}} \newline {\bf{{\emph{2.5}}}}} \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}{areaOfCircle(r)}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{def areaOfCircle(r): \newline if r \textless{}= 0: \newline return "Error: invalid radius" \newline pi = 3.1415 \newline area = pi {\emph{ r }}* 2 \newline return area \newline user\_radius = float(input("Enter the radius:")) \newline print ('The area of the circle is', \seqsplit{areaOfCircle(user\_radius))}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Enter the radius:300 \newline The area of the circle is 282735.0 \newline Enter the radius:0 \newline The area of the circle is Error: invalid radius} \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}{\_var1}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\_var1 = 1 \newline \_var1 = 3 \newline \_var1 + 100 \newline print(\_var1)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{3} \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}{maxlist}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{def maxlist(list): \newline maxvalue = list{[}0{]} \newline for item in list: \newline if item \textgreater{} maxvalue: \newline maxvalue = mylist \newline return maxlist \newline mylist = {[}21365741,2135416,2,54131,1.1515{]} \newline print(maxlist(mylist))} \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}{maxvalue}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{def max2(num1,num2): \newline maxvalue = num1 \newline if num2 \textgreater{} maxvalue: \newline maxvalue = num2 \newline return maxvalue \newline print('The largest number is',max2(2,3)) \newline print('The largest number is',max2(12222,10)) \newline \newline def max3(num1,num2,num3): \newline maxvalue = num1 \newline if num2 \textgreater{} maxvalue: \newline maxvalue = num2 \newline if num3 \textgreater{} maxvalue: \newline maxvalue = num3 \newline \newline return maxvalue \newline print('The largest number is',max3(1,5,10)) \newline print('The largest number is',max3(12222,5,10)) \newline print('The largest number is',max3(12222,164.3415645,121348561240))} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{The largest number is 3 \newline The largest number is 12222 \newline The largest number is 10 \newline The largest number is 12222 \newline The largest number is 121348561240} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.59264 cm} x{3.38436 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Multiplication and Exponents}} \tn % Row 0 \SetRowColor{LightBackground} string * number & combine that string multiple times \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} string * string & crash \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} number * number & math - multiply \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} string ** string & crash \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} number ** number & math - multiply \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} string ** number & crash \tn % Row Count 12 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.38896 cm} x{2.58804 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Addition}} \tn % Row 0 \SetRowColor{LightBackground} string + string & combine together \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} string + number & crash \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} number + number & math-addition \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.14011 cm} x{2.83689 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Conditionals}} \tn % Row 0 \SetRowColor{LightBackground} If..... :then..... else....... & If the statement is true then do command under then else do command under else \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} while...... & While this is true loop the command under the conditiona \tn % Row Count 7 (+ 3) % Row 2 \SetRowColor{LightBackground} While True & loops forever \tn % Row Count 8 (+ 1) % Row 3 \SetRowColor{white} for each item in name of list & For every item in the list repeat the command under the loop that many times. (a string is a list too) \tn % Row Count 13 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Big or small code}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{mystr = "hello THERE" \newline print (mystr.upper()) \newline print (mystr.lower()) \newline print (mystr.capitalize()) \newline print (mystr.title())} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{HELLO THERE \newline hello there \newline Hello there \newline Hello There} \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}{Please enter a number Code}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{user\_number = input("Please enter a number: ") \newline \newline number = int(user\_number) \newline \newline countdown\_string = '' \newline \newline while number \textgreater{} 0: \newline countdown\_string = countdown\_string+ str(number) \newline \newline number = number-1 \newline \newline print (countdown\_string)} \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}{Sort word per line}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{mystr = "Hello" \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}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{H \newline e \newline l \newline l \newline o} \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}{Shoping List code}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{shoppinglist = {[}'shoes', 'bags', 'shirts', 'pants'{]} \newline % Row Count 2 (+ 2) index = 0 \newline % Row Count 3 (+ 1) while index \textless{} len(shoppinglist): \newline % Row Count 4 (+ 1) print (shoppinglist{[}index{]}) \newline % Row Count 5 (+ 1) index = index + 1 \newline % Row Count 6 (+ 1) for item in shoppinglist: \newline % Row Count 7 (+ 1) print (item)% Row Count 8 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{shoes \newline bags \newline shirts \newline pants \newline shoes \newline bags \newline shirts \newline pants} \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}{printDefinitions}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{def printDefinitions(word): \newline if word =="variable": \newline print ('....') \newline elif word =="function": \newline print ('....') \newline elif word =="parameter": \newline print ('....') \newline elif word =="argument": \newline print ('....') \newline elif word =="function call": \newline print ('....') \newline elif word=="string": \newline print ('....') \newline else: \newline print("unknown word") \newline return \newline while True: \newline user\_input = input("Enter word: ") \newline \seqsplit{printDefinitions(user\_input)}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Enter word:} \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 a triangle}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{def areaofTriangle(b, h): \newline area = 0.5 {\emph{ b }} h \newline return area \newline user\_base = float(input('Enter the base of the triangle:')) \newline user\_height = float(input('Enter the height of the triangle:')) \newline print('The area of the triangle is',areaofTriangle(user\_base, user\_height)) \newline \newline def volumeofPrism(b,h,l): \newline volume = areaofTriangle(b, h) *l \newline return volume \newline user\_lenght = float(input('Enter the length of the prism: ')) \newline print('The volume of the prism is',volumeofPrism(user\_base, user\_height, user\_lenght) )} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Enter the base of the triangle:11111 \newline Enter the height of the triangle:2222 \newline The area of the triangle is 12344321.0 \newline Enter the length of the prism: 3333 \newline The volume of the prism is 41143621893.0} \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}{doubleIt(number)}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{def doubleIt(number): \newline return number*2 \newline print (doubleIt(3)) \newline print (doubleIt(doubleIt(4))) \newline \newline myvar = 12 \newline myvar= doubleIt(myvar) \newline myvar= doubleIt(myvar) \newline print(myvar)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{6 \newline 16 \newline 48} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}