\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{noeyarp} \pdfinfo{ /Title (python.pdf) /Creator (Cheatography) /Author (noeyarp) /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}{A30F22} \definecolor{LightBackground}{HTML}{F9F0F1} \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}{noeyarp} via \textcolor{DarkBackground}{\uline{cheatography.com/25806/cs/6980/}}} \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}noeyarp \\ \uline{cheatography.com/noeyarp} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 15th February, 2016.\\ Updated 10th 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{1.89126 cm} x{3.08574 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Functions}} \tn % Row 0 \SetRowColor{LightBackground} print() & displays information on the screen. \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} input() & receives information from the user. \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} int() & converts a value to an integer. \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} float() & change number to be decimal number. \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} str() & a list of number,letter and symbols. \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} len() & the length of the string. \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} \# & Comment or no effect \tn % Row Count 13 (+ 1) % Row 7 \SetRowColor{white} long (long integers ) & Also called longs, they are integers of unlimited size, written like integers and followed by an uppercase or lowercase L. \tn % Row Count 19 (+ 6) % Row 8 \SetRowColor{LightBackground} complex (complex numbers) & are of the form a + bJ, where a and b are floats and J (or j) represents the square root of -1 (which is an imaginary number). The real part of the number is a, and the imaginary part is b. Complex numbers are not used much in Python programming. \tn % Row Count 30 (+ 11) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.4977 cm} p{0.4977 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Code}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{} \tn % Row Count 0 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{name = "noey RAWIDA" \newline print (name.upper()) \newline print (name.lower()) \newline print (name.capitalize()) \newline print (name.title())} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.54747 cm} x{4.42953 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Conditional}} \tn % Row 0 \SetRowColor{LightBackground} if & A statement that the writer given a condition \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} else & A statement that can be combined with an if statement. \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} elif & A statement that allows you to check multiple expressions for TRUE and execute a block of code as soon as one of the conditions evaluates to TRUE. \tn % Row Count 9 (+ 5) % Row 3 \SetRowColor{white} while & A statement that acting resembles like a loop. \tn % Row Count 11 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Number to Binary 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}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Number to Binary 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}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Random Code}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{import random \newline \newline mylist = {[}'Dog','Fish', 'Cat', 'Bear'{]} \newline \newline counter = 0 \newline \newline while counter \textless{} 10: \newline random\_item = random.choice (mylist) \newline print (random\_item) \newline counter = counter + 1} \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}{Python Identifier}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Definition}} & is a name used to identify a variable, function, class, module or other object. An identifier starts with a letter A to Z or a to z or an underscore (\_) followed by zero or more letters, underscores and digits (0 to 9). \tn % Row Count 8 (+ 8) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.8308 cm} x{2.2885 cm} p{0.4577 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{5.377cm}}{\bf\textcolor{white}{Python Assignment Operators}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Operator}} & {\bf{Description}} & **E \tn % Row Count 1 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{0.82386 cm} x{1.87657 cm} x{1.87657 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{5.377cm}}{\bf\textcolor{white}{Python Assignment Operators}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{3}{x{5.377cm}}{} \tn % Row Count 0 (+ 0) % Row 1 \SetRowColor{white} {\bf{Operator}} & {\bf{Description}} & {\bf{Example}} \tn % Row Count 2 (+ 2) % Row 2 \SetRowColor{LightBackground} = & Assigns values from right side operands to left side operand & c = a + b assigns value of a + b into c \tn % Row Count 6 (+ 4) % Row 3 \SetRowColor{white} +=Add AND & It adds right operand to the left operand and assign the result to left operand & c += a is equivalent to c = c + a \tn % Row Count 11 (+ 5) % Row 4 \SetRowColor{LightBackground} \seqsplit{-=Subtract} AND & It subtracts right operand from the left operand and assign the result to left operand & c -= a is equivalent to c = c - a \tn % Row Count 17 (+ 6) % Row 5 \SetRowColor{white} \seqsplit{*=Multiply} AND & It multiplies right operand with the left operand and assign the result to left operand & c {\emph{= a is equivalent to c = c }} a \tn % Row Count 23 (+ 6) % Row 6 \SetRowColor{LightBackground} \seqsplit{/=Divide} AND & It divides left operand with the right operand and assign the result to left operand & c /= a is equivalent to c = c / ac /= a is equivalent to c = c / a \tn % Row Count 29 (+ 6) % Row 7 \SetRowColor{white} \seqsplit{\%=Modulus} AND & It takes modulus using two operands and assign the result to left operand & c \%= a is equivalent to c = c \% a \tn % Row Count 34 (+ 5) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{0.82386 cm} x{1.87657 cm} x{1.87657 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{5.377cm}}{\bf\textcolor{white}{Python Assignment Operators (cont)}} \tn % Row 8 \SetRowColor{LightBackground} \seqsplit{**=Exponent} AND & Performs exponential (power) calculation on operators and assign value to the left operand & c {\bf{= a is equivalent to c = c }} a \tn % Row Count 6 (+ 6) % Row 9 \SetRowColor{white} \seqsplit{//=Floor} \seqsplit{Division} & It performs floor division on operators and assign value to the left operand & c //= a is equivalent to c = c // a \tn % Row Count 11 (+ 5) \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{1.54287 cm} x{3.43413 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 - exponents \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{0.9954 cm} x{3.9816 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Data Types}} \tn % Row 0 \SetRowColor{LightBackground} Integer & -256, 15 \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} Float & -253.23, 1.253e-10 \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} String & " Hel lo", 'Goodbye', " " " Mul til ine " " " \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} Boolean & True,False \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} List & {[} value, ... {]} \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} Tuple & ( value, ... )1 \tn % Row Count 7 (+ 1) % Row 6 \SetRowColor{LightBackground} \seqsplit{Dictionary} & \{ key: value, ... \} \tn % Row Count 9 (+ 2) % Row 7 \SetRowColor{white} Set & \{ value, value, ... \}2 \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}{Loop list Code}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{def creatlist(quitword) : \newline print ('Keep entering words to add to the list') \newline print ('Quit when word =', quitword) \newline \newline mylist = {[}{]} \newline \newline while True: \newline user\_word = input('Enter a word to add to the list:') \newline \newline if user\_word == quitword \newline return mylist \newline duplicateword = False \newline \newline for item in mylist: \newline if item == user\_word: \newline duplicateword = True \newline \newline for item == user\_word: \newline duplicateword = True \newline \newline if duplicateword == True: \newline print ('Duplicate Word') \newline else: \newline \seqsplit{mylist.append(user\_word)} \newline \newline userlist = createList("stop") \newline print(userlist)} \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}{Random Choice Code}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{import random \newline mylist = {[}'beagle','pomeranian','pug','golden','chihuahua'{]} \newline score = 0 \newline chances = 3 \newline start\_over = 0 \newline random\_item = random.choice(mylist) \newline \newline while chances \textgreater{} 0: \newline start\_over = 0 \newline random\_item = random.choice(mylist) \newline \newline while start\_over \textless{} 1: \newline print \seqsplit{("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")} \newline print ("Guessing Game") \newline print \seqsplit{("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")} \newline print("words:", mylist) \newline guess = input("Guess a word: ") \newline \newline if (guess in mylist): \newline \newline if(guess == random\_item ): \newline print("That's correct!") \newline score = score + 100 \newline print("Score:", score) \newline start\_over = 2 \newline else: \newline print("Sorry, wrong choice! ") \newline chances = int(chances) -1 \newline else: \newline print("Sorry, that is not even in the list") \newline chances = int(chances) -1 \newline \newline if(chances \textgreater{} 0): \newline print("Chances remaining:",chances) \newline else: \newline start\_over = 2 \newline print("Game Over! The word was ", random\_item) \newline print("Chance remaining:", chances) \newline print("Final score:", score)} \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}{Python Shop Code}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{print ("welcone to our shop") \newline price=0 \newline size=('s','m','l','xl') \newline colour=('red','black','white') \newline sock=('want','not want') \newline \newline print (size) \newline shirt = (input('what shirt size do you want?')) \newline if shirt == ('s'): \newline price = price+70 \newline print( "the price now is",price) \newline elif shirt ==('m'): \newline price = price+80 \newline print( "the price now is",price) \newline elif shirt ==('l'): \newline price = price+90 \newline print( "the price now is",price) \newline elif shirt ==('xl'): \newline price = price+100 \newline print( "the price now is",price) \newline else: \newline print("our shop doesn't have this size.") \newline \newline \newline print (colour) \newline shirtcolour= (input('what colour of shirt do you want?')) \newline if shirtcolour == ('red'): \newline price = price+70 \newline print( "the price now is",price) \newline elif shirtcolour ==('black'): \newline price = price+80 \newline print( "the price now is",price) \newline elif shirtcolour ==('white'): \newline price = price+90 \newline print( "the price now is",price) \newline else: \newline print("our shop don't have this colour") \newline \newline print (size) \newline pant = (input('what pant size do you want?')) \newline if pant == ('s'): \newline price = price+70 \newline print( "the price now is",price) \newline elif pant ==('m'): \newline price = price+80 \newline print( "the price now is",price) \newline elif pant ==('l'): \newline price = price+90 \newline print( "the price now is",price) \newline elif pant ==('xl'): \newline price = price+100 \newline print( "the price now is",price) \newline else: \newline print("our shop doesn't have this size.choose again")} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.69218 cm} x{3.28482 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Data Type Conversion}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Function}} & {\bf{Description}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} int(x {[},base{]}) & Converts x to an integer. base specifies the base if x is a string. \tn % Row Count 4 (+ 3) % Row 2 \SetRowColor{LightBackground} float(x) & Converts x to a floating-point number. \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} long(x {[},base{]} ) & Converts x to a long integer. base specifies the base if x is a string. \tn % Row Count 9 (+ 3) % Row 4 \SetRowColor{LightBackground} str(x) & Converts object x to a string representation. \tn % Row Count 11 (+ 2) % Row 5 \SetRowColor{white} repr(x) & Converts object x to an expression string. \tn % Row Count 13 (+ 2) % Row 6 \SetRowColor{LightBackground} complex(real {[},imag{]}) & Create a complex number. \tn % Row Count 15 (+ 2) % Row 7 \SetRowColor{white} eval(str) & Evaluates a string and returns an object. \tn % Row Count 17 (+ 2) % Row 8 \SetRowColor{LightBackground} tuple(s) & Converts s to a tuple. \tn % Row Count 18 (+ 1) % Row 9 \SetRowColor{white} list(s) & Converts s to a list \tn % Row Count 19 (+ 1) % Row 10 \SetRowColor{LightBackground} set(s) & Converts s to a set. \tn % Row Count 20 (+ 1) % Row 11 \SetRowColor{white} dict(d) & Creates a dictionary, d must be a sequence of (key,value) tuples. \tn % Row Count 23 (+ 3) % Row 12 \SetRowColor{LightBackground} frozenset(s) & Converts to a frozen set. \tn % Row Count 24 (+ 1) % Row 13 \SetRowColor{white} chr(x) & Converts an integer to a character. \tn % Row Count 26 (+ 2) % Row 14 \SetRowColor{LightBackground} unichr(x) & Converts an integer to a Unicode character. \tn % Row Count 28 (+ 2) % Row 15 \SetRowColor{white} ord(x) & Converts a single character to its interger value. \tn % Row Count 30 (+ 2) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{1.69218 cm} x{3.28482 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Data Type Conversion (cont)}} \tn % Row 16 \SetRowColor{LightBackground} hex(x) & Converts an integer to a hexadecimal string. \tn % Row Count 2 (+ 2) % Row 17 \SetRowColor{white} oct(x) & Converts an interger to an octal string. \tn % Row Count 4 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.4977 cm} p{0.4977 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Python Variables Types}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{Number} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{String} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{List} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{Tuple} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{Dictionary} \tn % Row Count 5 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.09494 cm} x{3.88206 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Loop}} \tn % Row 0 \SetRowColor{LightBackground} While Loop & Repeats a statement or group of statements while a given condition is TRUE. It tests the condition before executing the loop body. \tn % Row Count 5 (+ 5) % Row 1 \SetRowColor{white} For Loop & Executes a sequence of statements multiple times and abbreviates the code that manages the loop variable. \tn % Row Count 9 (+ 4) % Row 2 \SetRowColor{LightBackground} Nested Loop & You can use one or more loop inside any another while, for or do..while loop. \tn % Row Count 12 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.4577 cm} x{1.87657 cm} x{2.24273 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{5.377cm}}{\bf\textcolor{white}{Math}} \tn % Row 0 \SetRowColor{LightBackground} != & unequal or not equal to & \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} == & equal to & example;(a == b) is not true. \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \textless{} & less than & example;(a \textless{} b) is true. \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \textgreater{} & more than & example;(a \textgreater{} b) is not true. \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} \textless{}= & less than or equal & example;(a \textless{}= b) is true. \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} \textgreater{}= & more than or equal & example;(a \textgreater{}= b) is not true. \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} \% & modulo or find the remainder & \tn % Row Count 14 (+ 2) % Row 7 \SetRowColor{white} \textless{}\textgreater{} & If values of two operands are not equal, then condition becomes true. & example;(a \textless{}\textgreater{} b) is true. This is similar to != operator. \tn % Row Count 19 (+ 5) \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 & holds a value and can be changed. \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} string & a list of characters such as numbers, letters, symbols. \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} integer number & whole number or 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} value & the number or the string can be store in valuable. \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{loop} \tn % Row Count 13 (+ 1) % Row 7 \SetRowColor{white} module & the text for storing for python code. \tn % Row Count 15 (+ 2) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{blank} \tn % Row Count 16 (+ 1) % Row 9 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{comment} \tn % Row Count 17 (+ 1) % Row 10 \SetRowColor{LightBackground} input & receives information from the user. \tn % Row Count 19 (+ 2) % Row 11 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{code} \tn % Row Count 20 (+ 1) % Row 12 \SetRowColor{LightBackground} print & to show information. \tn % Row Count 21 (+ 1) % Row 13 \SetRowColor{white} syntax error & make possible to the parse \tn % Row Count 23 (+ 2) % Row 14 \SetRowColor{LightBackground} boolean & true/false \tn % Row Count 24 (+ 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}{Statements}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{If Statement}} \newline % Row Count 1 (+ 1) if expression: \newline % Row Count 2 (+ 1) statements \newline % Row Count 3 (+ 1) elif expression: \newline % Row Count 4 (+ 1) statements \newline % Row Count 5 (+ 1) else: \newline % Row Count 6 (+ 1) statements \newline % Row Count 7 (+ 1) {\bf{While Loop}} \newline % Row Count 8 (+ 1) while expression: \newline % Row Count 9 (+ 1) statements \newline % Row Count 10 (+ 1) {\bf{For Loop}} \newline % Row Count 11 (+ 1) for var in collection: \newline % Row Count 12 (+ 1) statements \newline % Row Count 13 (+ 1) {\bf{Counting For Loop}} \newline % Row Count 14 (+ 1) for i in range(s t art, end {[}, step{]}): \newline % Row Count 15 (+ 1) statements \newline % Row Count 16 (+ 1) (start is included; end is not)% Row Count 17 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{0.86963 cm} x{2.19696 cm} x{1.51041 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{5.377cm}}{\bf\textcolor{white}{Python Arithmetic Operators}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Operator}} & {\bf{Description}} & {\bf{Example}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} + \seqsplit{Addition} & Adds values on either side of the operator. & a + b = 30 \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} - \seqsplit{Subtraction} & Subtracts right hand operand from left hand operand. & a - b = 30 \tn % Row Count 8 (+ 3) % Row 3 \SetRowColor{white} * \seqsplit{Multiplication} & Multiplies values on either side of the operator. & a * b = 200 \tn % Row Count 11 (+ 3) % Row 4 \SetRowColor{LightBackground} / \seqsplit{Division} & Divides left hand operand by right hand operand. & b / a = 2 \tn % Row Count 14 (+ 3) % Row 5 \SetRowColor{white} \% \seqsplit{Modulus} & Divides left hand operand by right hand operand and returns remainder. & b \% a = 0 \tn % Row Count 18 (+ 4) % Row 6 \SetRowColor{LightBackground} ** \seqsplit{Exponent} & Performs exponential (power) calculation on operators. & a ** b = 10 to the power 20 \tn % Row Count 21 (+ 3) % Row 7 \SetRowColor{white} // & Floor Division - The division of operands where the result is the quotient in which the digits after the decimal point are removed. & 9//2 = 4 and 9.0/2.0 = 4.0 \tn % Row Count 28 (+ 7) \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 Code}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{while True: \newline \newline user\_radius = input("What is the radius?") \newline radius = float(user\_radius) \newline pi = 3.1415 \newline area= pi radius * 2 \newline print ("The area of the circle is", area)} \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}{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}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Print Code}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{name = "noey RAWIDA" \newline print (name.upper()) \newline print (name.lower()) \newline print (name.capitalize()) \newline print (name.title())} \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 Code}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{shoppinglist = {[}'tshirt' , 'pants' , 'socks'{]} \newline \newline for myvariable in shoppinlist: \newline print (myvariable) \newline \newline print (shoppinglist{[}1{]}) \newline \newline for number in range(5): \newline print (number)} \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}{Count Down Code}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\#create a program that receives a number from the user and count down from that number on the same line \newline \newline \#recive the number from the user as a string \newline user\_number= input("enter number") \newline \newline \#convert the user number to an integer \newline number = int(user\_number) \newline \newline \#setup the countdown string \newline countdown\_string = "" \newline \newline while number \textgreater{} 0: \newline \#add the number to the string \newline \#subtract 1 from the number \newline countdown\_string = countdown\_string + str(number) + "" \newline number = number-1 \newline \newline print (countdown\_string) \newline \newline \#output should look like this \newline \# if the user enter 5: \newline \#5 4 3 2 1 \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}{Random Code 2}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{import random \newline \newline intlist = {[}1,2,3,4{]} \newline random\_int = random.choice(intlist) \newline print(intlist,random\_int) \newline \newline fplist = {[}1.0, 2.0, 3.0, 4.0{]} \newline random\_fp = random.choice(fplist) \newline print(fplist,random\_fp) \newline \newline strlist ={[}'book','pen','bag','pencil'{]} \newline random\_str = random.choice(strlist) \newline print (strlist,random\_str) \newline \newline mylist = {[}1, 1.0, 'beagle' {]} \newline random\_item = random.choice(mylist) \newline print(mylist,random\_item) \newline \newline myvar1 = 1 \newline myvar2 = 2 \newline myvar3 = 3 \newline varlist ={[}myvar1, myvar2, myvar3{]} \newline random\_var = random.choice(varlist) \newline print(varlist,random\_var)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}