\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{infinitepos} \pdfinfo{ /Title (ifnpython.pdf) /Creator (Cheatography) /Author (infinitepos) /Subject (IFNpython 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}{6631A3} \definecolor{LightBackground}{HTML}{F5F2F9} \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{IFNpython Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{infinitepos} via \textcolor{DarkBackground}{\uline{cheatography.com/25874/cs/6992/}}} \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}infinitepos \\ \uline{cheatography.com/infinitepos} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 12th February, 2016.\\ Updated 13th 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.54287 cm} x{3.43413 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/Counting number (No decimal) \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} Float number & The number with decimal \tn % Row Count 7 (+ 1) % Row 4 \SetRowColor{LightBackground} Modulo & Find the remainder \tn % Row Count 8 (+ 1) % Row 5 \SetRowColor{white} Boolean & True/False \tn % Row Count 9 (+ 1) % Row 6 \SetRowColor{LightBackground} Syntax & Grammar/Structure of language \tn % Row Count 11 (+ 2) % Row 7 \SetRowColor{white} Function call & A call to use function \tn % Row Count 13 (+ 2) % Row 8 \SetRowColor{LightBackground} \seqsplit{Argument/Parameter} & Something you give to function \tn % Row Count 15 (+ 2) % Row 9 \SetRowColor{white} Function & Something that you can reuse the code \tn % Row Count 17 (+ 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}{function 1}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{def aisha(text): \newline print("{\bf{{\emph{" + str(text) + "}}}}") \newline return \newline \newline aisha(1) \newline aisha("hello") \newline aisha(1+2) \newline aisha("text") \newline \newline def chung(text,decoration): \newline print(decoration + str(text) + decoration) \newline return \newline \newline chung(123123213212, "++++") \newline chung("hello", "\textless{}\textless{}\textgreater{}\textgreater{}")} \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 area of circle}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{def areaOfCircle(r): \newline if r\textless{}= 0: \newline return "Error:radius \textless{}= 0" \newline pi = 3.1415 \newline area = pi {\emph{ r }} r \#or pi {\emph{ r }}*2 \newline return area \newline \newline user\_radius = input("Enter the radius: ") \newline radius = float(user\_radius) \newline print("The area of the circle is", areaOfCircle(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}{Grade A Exam}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{theList = {[}"A","B","C","D"{]} \newline for item in theList: \newline print(item) \newline \newline whileList = {[}"E","F","G","H"{]} \newline s = 0 \newline while s \textless{} len(whileList): \newline print(whileList{[}s{]}) \newline s += 1 \newline while True: \newline user\_input = input ("Enter the word: ") \newline if user\_input == "exit": \newline break \newline else: \newline print(len(user\_input)) \newline \newline def theFunction(): \newline while True: \newline user\_input = input ("Enter the word: ") \newline if user\_input == "stop": \newline break \newline return \newline \newline theFunction() \newline \newline def computeThis(a1,b2): \newline return (a1{\emph{b2) \newline print (computeThis(4,8)) \newline \newline def finalFunction(string): \newline print("{\bf{}}{\emph{"+string+"}}}}*") \newline return \newline finalFunction("Aisha")} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.89126 cm} x{3.08574 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Code}} \tn % Row 0 \SetRowColor{LightBackground} print (name.upper()) & Make every letter capital case \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} print (name.lower()) & Make every letter lower case \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} print \seqsplit{(name.capitalize())} & Make the first letter capital case \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} print (name.title()) & Make the first letter and the letter after the space capital case \tn % Row Count 9 (+ 3) \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}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{import random \newline \newline \# Create a list of integers \newline intlist ={[}1,2,3,4{]} \newline random\_int = random.choice(intlist) \newline print(intlist,random\_int) \newline \newline \# Create a list of floating point numbers \newline fplist = {[}1.0,1.2,1.4,0.5{]} \newline random\_fp = random.choice(fplist) \newline print(fplist,random\_fp) \newline \newline \# Create a list of strings \newline srtlist = {[}"Aisha","Eve","KamitoP","Sanya"{]} \newline random\_srt = random.choice(srtlist) \newline print(srtlist,random\_srt) \newline \newline \# Create a list of integer, floating point number and string \newline mylist = {[}1,2.5,"Aisha"{]} \newline random\_item = random.choice(mylist) \newline print(mylist,random\_item) \newline \newline \# Create a list of following variables \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} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Max Value Function}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{def max2(num1,num2): \newline MaX = num2 \newline if num1 \textgreater{} num2: \newline MaX = num1 \newline return MaX \newline def max3(num1,num2,num3): \newline Max = num1 \newline if num2 \textgreater{} num1: \newline if num2 \textgreater{} num3: \newline Max = num2 \newline if num3 \textgreater{} num1: \newline if num3 \textgreater{} num1: \newline Max = num3 \newline return Max \newline \newline first = input('Enter the first number: ') \newline second = input('Enter the second number: ') \newline third = input('Enter the thrid number: ') \newline \newline print("Max value of 2 value is",max2(first,second)) \newline print("Max value of 2 value is",max3(first,second,third))} \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 Word}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{while True: \newline word = input("Please enter the word:" ) \newline index = 0 \newline reverse = '' \newline \newline while int(index)\textless{}len(word): \newline reverse = word{[}index{]} + (reverse) \newline index = int(index) + 1 \newline \newline print("Reverse: ", reverse)} \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 to binary}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{user\_number = ' ' \newline \newline while user\_number != ' 0 ' : \newline user\_number = input ("Enter a number to convert to binary: ") \newline number = int(user\_number) \newline binary\_string = ' ' \newline \newline while (number \textgreater{} 0): \newline remainder = number\%2 \newline binary\_string = str(remainder)+ binary\_string \newline number = number//2 \newline \newline print ("Binary string is", binary\_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}{Palindrome 9/10}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{def isPalindrome(word): \newline reverse = "" \newline \newline for item in word: \newline reverse = item + reverse \newline \newline if reverse == word: \newline return True \newline else: \newline return False \newline \newline while True: \newline user\_word = input('What is the word: ') \newline length = len(user\_word) \newline if user\_word == 'quit': \newline break \newline else: \newline print("Length of the word is: ",(length)) \newline \newline function\_return = isPalindrome(user\_word) \newline if function\_return == True: \newline print(user\_word, "is a palindrome") \newline else: \newline print(user\_word, "is not a palidrome")} \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 Function}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{def areaOfTriangle(base,height): \newline return (1/2{\emph{base}}height) \newline \newline user\_base = float(input('Enter the base of triangle: ')) \newline user\_height = float(input('Enter the height of triangle: ')) \newline \newline print ('The area of Triangle is: ',areaOfTriangle(user\_base,user\_height)) \newline \newline def volumeOfPrism(area,dept): \newline return (area*dept) \newline user\_dept = float(input('Enter the dept of the Prism: ')) \newline print ('The volume of Prism is: ',volumeOfPrism(areaOfTriangle(user\_base,user\_height),(user\_dept)))} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}