\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{Chutima Rakyu} \pdfinfo{ /Title (python-cheat-sheet-muids.pdf) /Creator (Cheatography) /Author (Chutima Rakyu) /Subject (python MUIDS 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}{846FA3} \definecolor{LightBackground}{HTML}{F7F6F9} \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 MUIDS Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Chutima Rakyu} via \textcolor{DarkBackground}{\uline{cheatography.com/25741/cs/6857/}}} \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}Chutima Rakyu \\ \uline{cheatography.com/chutima-rakyu} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 3rd February, 2016.\\ Updated 6th 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{2.33919 cm} x{2.63781 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Functions}} \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} " " " .... " " " & comment(many lines) \tn % Row Count 8 (+ 1) % Row 4 \SetRowColor{LightBackground} str() & a list of number, letter and symbols \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} \# & comment(one line) \tn % Row Count 11 (+ 1) % Row 6 \SetRowColor{LightBackground} input() & receive information from user \tn % Row Count 13 (+ 2) % Row 7 \SetRowColor{white} import random + \seqsplit{random.choice(list)} & pick random item from the list \tn % Row Count 15 (+ 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}{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} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Print Code}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{name = "nae CHUTIMA" \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}{number to binary code}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{user\_number = "" \newline while user\_number != "0": \newline \newline user\_number = input ( "enter a number" ) \newline \newline number = int(user\_number) \newline \newline binary\_string = "" \newline while (number \textgreater{} 0 ):\#the number is greater than 0 \newline remainder = number \% 2 \newline binary\_string = str( remainder )+ binary\_string \newline number = number//2 \newline print (number) \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}{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}{The loop not go forever}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{gameover = 0 \newline \newline while(gameover == 0): \newline print ("hello") \newline gameover = 1} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{print number in separate line in list mylist}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{mylist = {[}1,2,3,4,5{]} \newline \newline for number in mylist: \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}{using a while loop to print each item in list}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{wlist = {[}2,4,5,6,7,8{]} \newline index = 0 \newline \newline while index \textless{} len(wlist): \newline print (wlist{[}index{]}) \newline index = index +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}{Definition Area}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{def areaOfTriangle (base,height): \newline return base {\emph{ heigh }} 0.5 \newline \newline base = float(input('Enter the base of the triangle')) \newline height = float(input(input('Enter the height of the triangle: ')) \newline \newline print('The area of the triangle is',areaOfTriangle(base,height)) \newline \newline def volumeOfPrism (area,height) \newline return areaOfPrism* height \newline \newline base = float(input('Enter the area of the prism')) \newline height = float(input(input('Enter the height of the prism: '))} \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}{Import random}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{import random \newline \#create list \newline \newline mylist = {[}'nadia' , 'nat' , 'lily' , 'eye'{]} \newline \newline \#print(mylist{[}0{]}) \newline \newline \# select a random item from the list \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} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{The loop not go forever (copy)}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{gameover = 0 \newline \newline while(gameover == 0): \newline print ("hello") \newline gameover = 1} \tn \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.28942 cm} x{2.68758 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Multiplication and Exponents}} \tn % Row 0 \SetRowColor{LightBackground} string * number & combine that string \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} string* string & crash \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} number * number & math - multiply \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} string ** string & crash \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} number ** number & math - exponent \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} string ** number & crash \tn % Row Count 6 (+ 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}{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 {\emph{ 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}{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}{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} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{print fifth character from the variable myword}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{myword = "hellothere" \newline print ( myword{[}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}{convert input to a integer multiply by 10}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{while True: \newline user\_number = input("Enter the number") \newline number = int(user\_number)*10 \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}{convert input to a integer multiply by 10}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{while True: \newline user\_number = input("Enter the number") \newline number = int(user\_number)*10 \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}{palindrome}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{while True: \newline def palindrome(word): \newline reverse = "" \newline myresult = "" \newline for letters in word: \newline reverse = letters + reverse \newline \newline if word == reverse : \newline return True \newline else: \newline return False \newline reverse = "" \newline \newline word = input("please enter a word: ") \newline if word == "quit": \newline break \newline theresult = palindrome(word) \newline print("This word has",len(word),"letter") \newline \newline \newline if theresult == True: \newline print(True,'',word + str('It is a palindrome')) \newline else: \newline print(False,'',word +str('It is not a palindrome'))} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.4977 cm} x{4.4793 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Math}} \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) \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 change \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} string & a list of character such as number, letter and 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 or structure of lauguage \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} value & the number or string can be store in valuable \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} module & the text for storing for python code or find the remainder \tn % Row Count 14 (+ 2) % Row 7 \SetRowColor{white} input & gain information from user \tn % Row Count 15 (+ 1) % Row 8 \SetRowColor{LightBackground} print & to show information on the screen \tn % Row Count 17 (+ 2) % Row 9 \SetRowColor{white} syntax error & make impossible to the parse \tn % Row Count 19 (+ 2) % Row 10 \SetRowColor{LightBackground} boolean & true/false \tn % Row Count 20 (+ 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}{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}{using loop to print out each item in list}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{forlist = {[}'hi','hello','bye'{]} \newline for word in forlist: \newline print(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}{create list}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\# create a function that allows a user to create a list \newline \newline \#function name: word \newline \#paramater: word \newline \#return the list \newline \newline def createList (quitword): \newline mylist = {[}{]} \#create an empty list \newline \newline while True: \newline \#get the item from the user \newline item = input('Please enter a list item') \newline \newline \# when the user enters an item that is equal to quitword \newline if item == quitword: \newline return mylist \newline \# check if the list already in the list \newline duplicateword = False \newline \# figure out if the word is already in the list \newline \newline for word in mylist: \newline if item == word: \newline duplicateword = True \newline if duplicateword == True \newline print ('Duplicate word!') \newline else: \newline \# add this item to the end of the list \newline mylist.append(item) \newline \newline \#function call \newline mylist = creatList("stop") \newline print(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}{Definition in each word}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{def printDefinitions(word): \newline \newline if word == "variable": \newline print(""" \newline 'A variable is things that able to change' \newline """) \newline \newline elif word == "function": \newline print(""" \newline "A function is to help to use a code" \newline """) \newline elif word == "variable": \newline print(""" \newline 'A variable is the things that help you to change' \newline """) \newline \newline elif word == "return variable": \newline print(""" \newline 'A return variable is something that return the function back to you' \newline """) \newline elif word == "argument": \newline print(""" \newline 'A argument is something that give the function to you' \newline """) \newline elif word == "parameter": \newline print(""" \newline 'A parameter is something that give function' \newline """) \newline elif word == "string": \newline print(""" \newline 'A string is the text, number or anything that is list the characters' \newline """) \newline else: \newline print(""" \newline 'unknown word' \newline """) \newline \newline user\_word = input( "Enter a word to define: ") \newline printDefinitions(user\_word)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}