\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{mimi} \pdfinfo{ /Title (mimi-s-python-skills.pdf) /Creator (Cheatography) /Author (mimi) /Subject (Mimi's python skills 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}{1CD994} \definecolor{LightBackground}{HTML}{F0FCF8} \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{Mimi's python skills Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{mimi} via \textcolor{DarkBackground}{\uline{cheatography.com/25752/cs/6875/}}} \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}mimi \\ \uline{cheatography.com/mimi} \\ \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 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*}{2} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Info4}} \tn \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Functions \newline % Row Count 1 (+ 1) \#function with no parameters/arguments \newline % Row Count 2 (+ 1) \#and no return value \newline % Row Count 3 (+ 1) \#return is optional if you do not return a value \newline % Row Count 4 (+ 1) def nameOfFunction(): \newline % Row Count 5 (+ 1) print ('This function has no parameters') \newline % Row Count 6 (+ 1) print ('This function has no return value') \newline % Row Count 7 (+ 1) return \# no value, just exits the function \newline % Row Count 8 (+ 1) \#function call \newline % Row Count 9 (+ 1) nameOfFunction() \newline % Row Count 10 (+ 1) \#function with 1 parameter/argument \newline % Row Count 11 (+ 1) def testFunction(param): \newline % Row Count 12 (+ 1) print ('This function has 1 parameter') \newline % Row Count 13 (+ 1) print (param) \newline % Row Count 14 (+ 1) \#function call \newline % Row Count 15 (+ 1) testFunction ("this is the parameter value") \newline % Row Count 16 (+ 1) \#function with 2 parameters and a return value \newline % Row Count 17 (+ 1) def function3(param1, param2): \newline % Row Count 18 (+ 1) print('This function has 2 parameters') \newline % Row Count 19 (+ 1) return param1 + param2 \# return value \newline % Row Count 20 (+ 1) \#function call and store the result in a variable \newline % Row Count 21 (+ 1) returnValue = function3(2, 3) \newline % Row Count 22 (+ 1) print (returnValue)% Row Count 23 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{info3}} \tn \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Lists: \newline % Row Count 1 (+ 1) mylist = {[}2,3,4,5{]} \# create a list \newline % Row Count 2 (+ 1) \#select an item from a list \newline % Row Count 3 (+ 1) print (mylist{[}0{]}) \#selects first item and displays 2 \newline % Row Count 5 (+ 2) \# len() determines the length of the list \newline % Row Count 6 (+ 1) print (len(mylist)) \# displays 4 \newline % Row Count 7 (+ 1) mylist.append(5) \# adds an item to the end of the list \newline % Row Count 9 (+ 2) While Loop with List: \newline % Row Count 10 (+ 1) thelist = {[}4, 3, 2, 1, 0{]} \newline % Row Count 11 (+ 1) index = 0 \# start at the first item \newline % Row Count 12 (+ 1) while index \textless{} len(thelist): \newline % Row Count 13 (+ 1) print (thelist{[}index{]}) \#prints each item \newline % Row Count 14 (+ 1) index = index + 1 \newline % Row Count 15 (+ 1) For-Loop with List: \newline % Row Count 16 (+ 1) forlist = {[}3, 4, 5, 2, 1{]} \newline % Row Count 17 (+ 1) for item in forlist: \newline % Row Count 18 (+ 1) print(item) \newline % Row Count 19 (+ 1) Range() \newline % Row Count 20 (+ 1) \#creates a list of numbers from 0 to the specified \newline % Row Count 22 (+ 2) number \newline % Row Count 23 (+ 1) numberlist = range(5) \newline % Row Count 24 (+ 1) \# is the same as creating the following list \newline % Row Count 25 (+ 1) numberlist2 = {[}0, 1, 2, 3, 4{]} \newline % Row Count 26 (+ 1) for num in range(100): \newline % Row Count 27 (+ 1) print (num) \# prints all numbers from 0 – 99 \newline % Row Count 28 (+ 1) for num in range(5, 50): \newline % Row Count 29 (+ 1) print(num) \#prints all numbers from 5 - 49% Row Count 30 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Python4-Methods}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\#Mill's method \newline word= input("Please enter yout word") \newline index= len(word)-1 \newline reverse= '' \newline while (index\textgreater{}-1): \newline reverse=reverse+word{[}index{]} \newline index=index-1 \newline print (reverse) \newline \newline \#mr's method \newline word= input("Please enter yout word") \newline index=0 \newline reverse='' \newline while index\textless{} len(word): \newline reverse=word{[}index{]}+ reverse \newline index=index+1 \newline print("reverse: ",reverse)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Python6}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{import random \newline \newline \#Create a list \newline \newline guesslist = {[}'grape', 'orange', 'chloroplast', 'ribosome', 'lipstick'{]} \newline \newline chance = 3 \newline score = 0 \newline \newline print (guesslist) \newline \newline while chance != 0: \newline random\_item = random.choice(guesslist) \newline user\_input = input("Please guess a word: ") \newline if user\_input == random\_item: \newline print ("That's correct!") \newline score = score + 100 \newline print ("Score:", score) \newline else: \newline if user\_input not in guesslist: \newline print ("Sorry, that isn't even in the list!") \newline chance = chance - 1 \newline print ("Chance Remaining:", chance) \newline else: \newline print ("Sorry, wrong choice!") \newline chance = chance - 1 \newline print ("Chance Remaining:", chance) \newline \newline if chance == 0: \newline print ("The word was", random\_item) \newline print ("The score is", score)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.6 cm} x{4.4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Keywords}} \tn % Row 0 \SetRowColor{LightBackground} print() & Show information that you want on the screen \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} int() & Change number to be number integer \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} float() & Change number to be decimal number \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} input() & Gain information from user \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} str() & A list of number, letter and symbols \tn % Row Count 11 (+ 2) % Row 5 \SetRowColor{white} len() & The length of the string \tn % Row Count 13 (+ 2) % Row 6 \SetRowColor{LightBackground} \# & Comment, no effect \tn % Row Count 14 (+ 1) % Row 7 \SetRowColor{white} import random + random.choice() & pick random item in the list \tn % Row Count 16 (+ 2) % Row 8 \SetRowColor{LightBackground} == & equal to \tn % Row Count 17 (+ 1) % Row 9 \SetRowColor{white} != & no equal to \tn % Row Count 18 (+ 1) % Row 10 \SetRowColor{LightBackground} \textless{} & less than \tn % Row Count 19 (+ 1) % Row 11 \SetRowColor{white} \textgreater{} & more than \tn % Row Count 20 (+ 1) % Row 12 \SetRowColor{LightBackground} \textless{}= & less than or equal \tn % Row Count 21 (+ 1) % Row 13 \SetRowColor{white} \textgreater{}= & more than or equal \tn % Row Count 22 (+ 1) % Row 14 \SetRowColor{LightBackground} \% & Modulo, Find the remainder \tn % Row Count 24 (+ 2) % Row 15 \SetRowColor{white} string + string & combine together \tn % Row Count 25 (+ 1) % Row 16 \SetRowColor{LightBackground} string + number & CRASH \tn % Row Count 26 (+ 1) % Row 17 \SetRowColor{white} number + number & addition (Math) \tn % Row Count 27 (+ 1) % Row 18 \SetRowColor{LightBackground} string * number & combine that string \tn % Row Count 28 (+ 1) % Row 19 \SetRowColor{white} string* string & CRASH \tn % Row Count 29 (+ 1) % Row 20 \SetRowColor{LightBackground} number * number & Multiply (Math) \tn % Row Count 30 (+ 1) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{3.6 cm} x{4.4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Keywords (cont)}} \tn % Row 21 \SetRowColor{LightBackground} number ** number & Exponent (Math) \tn % Row Count 1 (+ 1) % Row 22 \SetRowColor{white} string ** number & CRASH \tn % Row Count 2 (+ 1) % Row 23 \SetRowColor{LightBackground} Variable & Hold a value and can be change \tn % Row Count 4 (+ 2) % Row 24 \SetRowColor{white} String & A list of character such as number, letter and symbols \tn % Row Count 7 (+ 3) % Row 25 \SetRowColor{LightBackground} Integer number & Whole number/counting number \tn % Row Count 9 (+ 2) % Row 26 \SetRowColor{white} Floating point & The number in decimal \tn % Row Count 10 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{convert dec num into its Binary form}} \tn \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{number = int(input("Enter number: ")) \newline % Row Count 1 (+ 1) binary = " " \newline % Row Count 2 (+ 1) while number\textgreater{} 0: \newline % Row Count 3 (+ 1) remainder = number \% 2 \newline % Row Count 4 (+ 1) binary = str(remainder) + binary \newline % Row Count 5 (+ 1) number= number//2 \newline % Row Count 6 (+ 1) print(binary)% Row Count 7 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{determine whether user inout is pos or neg num}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{number = int(input("Enter number: ")) \newline if number\textgreater{}0: \newline print(number, "is positive") \newline print(number,"is negative")} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Python1-Methods}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{""" \newline Python Intro Assignment \#2 \newline name \newline student number \newline """ \newline \newline \#Ask the user for a radius of a circle \newline user\_radius =(input("What is the radius?")) \newline \#Convert the given radius to a floating point \newline radius= float(user\_radius) \newline \#make a variable called pi \newline pi = 3.1415 \newline \#Calculate the area of the circle using exponents \newline area =(pi{\emph{(radius}}*2)) \newline \#diaplay the area of the circle to the user \newline print("The area of the circle is", area)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{ask user for input}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{mylist = {[} {]} \newline for number in range(5): \newline mylist.append(input("Enter value: "))} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Ask the user fro input 5 items and add the values t a list called mylist, then print the list} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{largest value}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{number= {[}3, 2, 77, 32, 9, 8, 31{]} \newline largest = 0 \newline for value in number: \newline if number\textgreater{} largest: \newline largest = number \newline print (largest)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Determine the largest value from a given list} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{func take radius,give back a of circle A=pi r*r}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{def AreaOfCircle(radius): \newline A=3.14{\emph{radius}}radius \newline return A \newline num= int(input("Enter a radius: ")) \newline x= AreaOfCircle(num) \newline print(x)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{info2}} \tn \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Basic Math Operations: \newline % Row Count 1 (+ 1) + addition, - subtraction \newline % Row Count 2 (+ 1) / divide with answer as a float. E.g. 5/2 == 2.5 \newline % Row Count 3 (+ 1) // divide with answer as an integer. E.g. 5//2 == 2 \newline % Row Count 5 (+ 2) * multiply \newline % Row Count 6 (+ 1) {\bf{ exponent. E.g. 2 power 3 == 2 }} 3 \newline % Row Count 7 (+ 1) \% modulo. Gives the remainder when dividing \newline % Row Count 8 (+ 1) e.g. 33 \% 10 == 3 \newline % Row Count 9 (+ 1) All math operations use the same order of operations as \newline % Row Count 11 (+ 2) Math class. \newline % Row Count 12 (+ 1) Comparing Values: \newline % Row Count 13 (+ 1) When you compare two values, the result is a Boolean \newline % Row Count 15 (+ 2) (True or False) E.g. 2 == 3 is False \newline % Row Count 16 (+ 1)  == is equal to \newline % Row Count 17 (+ 1)  != is not equal to \newline % Row Count 18 (+ 1)  \textless{} less than \newline % Row Count 19 (+ 1)  \textless{}= less than or equal to \newline % Row Count 20 (+ 1)  \textgreater{} greater than \newline % Row Count 21 (+ 1)  \textgreater{}= greater than or equal to \newline % Row Count 22 (+ 1)  and \newline % Row Count 23 (+ 1)  or \newline % Row Count 24 (+ 1)  not \newline % Row Count 25 (+ 1) True or anything is always True \newline % Row Count 26 (+ 1) False and anything is always False \newline % Row Count 27 (+ 1) Forever While Loop \newline % Row Count 28 (+ 1) while True: \# forever \newline % Row Count 29 (+ 1) user\_input = input('Enter a number: ') \newline % Row Count 30 (+ 1) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{info2 (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{ number = int(user\_input) \newline % Row Count 1 (+ 1) print ('The number squared is', number ** 2) \newline % Row Count 2 (+ 1) Conditional While Loop: \newline % Row Count 3 (+ 1) count = 0 \# start at zero \newline % Row Count 4 (+ 1) while count \textless{} 10: \# loop while count is less than 10 \newline % Row Count 6 (+ 2) print(count) \#will print numbers 0 - 9 \newline % Row Count 7 (+ 1) count = count + 1 \# must increase count \newline % Row Count 8 (+ 1) Decision Making/Conditional Statements: \newline % Row Count 9 (+ 1) if 3 \textless{} 2: \#if statement must compare two Booleans \newline % Row Count 10 (+ 1) print ('3 is less than 2') \newline % Row Count 11 (+ 1) elif 4 \textless{} 2: \#can have 0 or more elif statements \newline % Row Count 12 (+ 1) print ('4 is less than 2') \newline % Row Count 13 (+ 1) elif 5 \textless{} 2: \newline % Row Count 14 (+ 1) print ('5 is less than 2') \newline % Row Count 15 (+ 1) else: \#can have 0 or 1 else statement at the end \newline % Row Count 16 (+ 1) print ('none of the above are True')% Row Count 17 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Info}} \tn \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Vocabulary: \newline % Row Count 1 (+ 1) syntax, variable, Boolean, string, integer, float, \newline % Row Count 3 (+ 2) list, comment, character, conditional, modulo, \newline % Row Count 4 (+ 1) if/elif/else, loop, range, parameter, argument, \newline % Row Count 5 (+ 1) function call, \newline % Row Count 6 (+ 1) Data Types: \newline % Row Count 7 (+ 1) String - a list of characters e.g. "abc123\$\%\textasciicircum{}", or \newline % Row Count 9 (+ 2) empty string "" \newline % Row Count 10 (+ 1) Integer - whole numbers, and negative numbers e.g. -5, \newline % Row Count 12 (+ 2) 0, 2, 99 \newline % Row Count 13 (+ 1) Floating Point - decimal numbers e.g. 1.5, 2.0, -2.99 \newline % Row Count 15 (+ 2) Boolean - True or False \newline % Row Count 16 (+ 1) User input: \newline % Row Count 17 (+ 1) user\_input = input("Enter a value: ") \newline % Row Count 18 (+ 1) Converting between different data types: \newline % Row Count 19 (+ 1) word = str(3) \#converts 3 to a string "3" \newline % Row Count 20 (+ 1) num = int("3.5") \#converts "3.5" to an integer 3 \newline % Row Count 21 (+ 1) num = float("3") \#converts "3" to a float 3.0 \newline % Row Count 22 (+ 1) Printing values: \newline % Row Count 23 (+ 1) print("hello", "there") \#displays hello there \newline % Row Count 24 (+ 1) print("hello" + "there") \#displays hellothere \newline % Row Count 25 (+ 1) Combining Strings (Concatenation) \newline % Row Count 26 (+ 1) "hi" + "there" == "hithere" \newline % Row Count 27 (+ 1) "hi" * 5 == "hihihihihi" \newline % Row Count 28 (+ 1) Comments \newline % Row Count 29 (+ 1) \# hashtag – everything after \# is a comment not code \newline % Row Count 31 (+ 2) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Info (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{""" \newline % Row Count 1 (+ 1) Double quote - Multi-line comment, everything in \newline % Row Count 2 (+ 1) between three double quotes is a comments \newline % Row Count 3 (+ 1) """ \newline % Row Count 4 (+ 1) ''' Single quote - Multi-line comment, everything in \newline % Row Count 6 (+ 2) between three single quotes is a comments '''% Row Count 7 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{stop the loop}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{mylist ={[} {]} \newline while True: \newline value = input("Enter value: ") \newline if value == "*" \newline break \newline else: \newline mylist.append(value) \newline \newline print (mylist)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{continuously ask the user for input if the user types star,stop the loop and print the list} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{create mylist: dont know what inside}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{for number in mylist: \newline print (number)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Create a program which prints every element from a list called mylist{[} {]} : you do not know what is inside the list} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{pattern based on user input}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{1= ! \newline 2= !! \newline !! \newline 3= !!! \newline !!! \newline !!!} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{determine whther user input is even or odd}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{number= int(input("Enter number: ")) \newline if number\%2 ==0: \newline print (number, "is even num") \newline else: \newline print (number, "is odd num")} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Python5-Methods}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\#lists \newline \newline shoppinglist = {[}'phone', 'battery', 'charger'{]} \newline \newline for item in shoppinglist: \newline print (item) \newline for number in range (1, 10): \newline print (number) \newline for number in range(5): \newline print (number) \newline \newline \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\# \newline \newline \#lists \newline \newline fruits= {[}{]}\#an empty list \newline \newline for number in range(5): \newline user\_fruit= input("Please enter a fruit") \newline \seqsplit{fruits.append(user\_fruit)} \newline print ("size of fruit list is", len(fruits)) \newline \newline for fruit in fruits: \newline print("Fruit: ", fruit)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Python2-Methods}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\#write a program that converts a number to binary \newline \newline \#get a number from the user \newline \newline user\_number = int(input("Enter a number to convert to binary: ")) \newline \newline \#while loop \newline \newline \# \newline \newline while (user\_number \textgreater{}0): \#the number is greater than 0) \newline remainder = \newline binary\_string = \newline binary\_string = \newline \newline \#after the loop print the binary string \newline print ("Binary string is", binary\_string) \newline \newline \#expected output - 5 =101 \newline \#expected output - 3 =11 \newline \#expected output - 2 =10} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Python3-Methods}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{number= int(input("What's your number?") \newline \newline while(number\textgreater{}=1): \newline \newline print(number) \newline number=number-1 \newline \newline convert= int(input("What do you want to convert to?")} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}