\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{mint.sirikorn} \pdfinfo{ /Title (python.pdf) /Creator (Cheatography) /Author (mint.sirikorn) /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}{BFBFBF} \definecolor{LightBackground}{HTML}{F7F7F7} \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}{mint.sirikorn} via \textcolor{DarkBackground}{\uline{cheatography.com/25740/cs/6859/}}} \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}mint.sirikorn \\ \uline{cheatography.com/mint-sirikorn} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 10th 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{2.38896 cm} x{2.58804 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 characters \tn % Row Count 9 (+ 1) % Row 5 \SetRowColor{white} len() & The length of the string \tn % Row Count 11 (+ 2) % Row 6 \SetRowColor{LightBackground} " " " .... " " " & comment (many lines) \tn % Row Count 12 (+ 1) % Row 7 \SetRowColor{white} \# & comment(one line) \tn % Row Count 13 (+ 1) % Row 8 \SetRowColor{LightBackground} import random + random.choice() & pick random item in the list \tn % Row Count 15 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.14471 cm} x{3.83229 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 number, letter, symbols \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} input & receives information from the user \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} float number & number with a decimal \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} syntax & structure of language or grammar \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} integer & whole number or counting number \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} print & displays information on the screen \tn % Row Count 14 (+ 2) % Row 7 \SetRowColor{white} value & the number or string can be store in valuable \tn % Row Count 16 (+ 2) % Row 8 \SetRowColor{LightBackground} syntax error & make impossible to the phase \tn % Row Count 18 (+ 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}{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 letter too 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}{Area of a triangle}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{def areaoftriangle(base, height): \newline return base{\emph{ height}} 1/2 \newline \newline base = float(input('Enter the base of the triangle: ')) \newline height = float(input('Enter the height of the triangle: ')) \newline \newline print ('The area of the triangle is', areaoftriangle(base, height))} \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 Palindrome}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{while True: \newline def ispalindrome(word): \newline reverse= "" \newline myresult= "" \newline for letter in word: \newline reverse= letter+ reverse \newline if word == reverse: \newline return True \newline else: \newline return False \newline reverse= "" \newline word= input("Please enter a word: ") \newline if word == "quit": \newline break \newline myresult= ispalindrome(word) \newline print("This word has", len(word),"letters") \newline if myresult== True: \newline print(True,',',word+str(" is a palindrome")) \newline else: \newline print(False,',',word+str(" is not a palindrome")) \newline \# Print: Please enter a word: kayak \newline This word has 5 letters \newline True , kayak is a palindrome \newline Please enter a word: mint \newline This word has 4 letters \newline False , mint is not a palindrome} \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}{Recieve number and determine number}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\textasciicircum{}9 is divisible by3\textasciicircum{} \newline \textasciicircum{}7 is not divisible by 3\textasciicircum{} \newline usernumber= input("Please enter the a number: ") \newline remainder= usernumber\%3 \newline if remainder ==0: \newline print(usernumber, "is divisible by 3") \newline else: \newline print(usernumber, "is not divisible by 3") \newline \textasciicircum{}4 is positive\textasciicircum{} \textasciicircum{}0 is zero\textasciicircum{} \textasciicircum{}-8 is negative\textasciicircum{} \newline usernum= input("Pls enter the number: ") \newline if usernum\textgreater{}0: \newline print(usernum, "is positive") \newline elif usernum==0: \newline print(usernum, "is zero") \newline else: \newline print(usernu, "is negative")} \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}{areaOFEllipse}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\# the function should be given two parameters and should return the area \newline def areofellipse(r1r2): \newline area= 3.14{\emph{r1}}r2 \newline return(area) \newline r1= float(input("Enter radius1: ")) \newline r2= float(input("Enter radius2: ")) \newline area= areaofellipse(r1,r2) \newline print(area)} \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}{Operation}} \tn % Row 0 \SetRowColor{LightBackground} == & equal to \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} != & not equal \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \textless{} & less than \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \textgreater{} & greater 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{}= & greater 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.59264 cm} x{3.38436 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Multiplication and Exponents}} \tn % Row 0 \SetRowColor{LightBackground} string * number & combine that string multiple times \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} string * string & crash \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} number * number & math - multiply \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} string ** string & crash \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} number ** number & math - 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} \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 a 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}{Random choice code}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{import random \newline mylist = {[}'cat','dog','chicken','bird','fish'{]} \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 ("-=-=-=-=-=-=-=-=-=") \newline print ("Guessing Game") \newline print ("-=-=-=-=-=-=-=-=-=") \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}{Convert number to binary}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{user\_number = " " \newline \newline while user\_number != "0": \newline \newline user\_number = input ("enter a number") \newline number = int(user\_number) \newline binary\_string = " " \newline \newline while (number\textgreater{}0): \newline \newline remainder = number \% 2 \newline binary\_string = str(remainder) + binary\_string \newline number = numbe//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}{code}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{def createlist(quitword): \newline mylist= {[}{]} \newline \newline while True: \newline item= input("Please enter a list item: ") \newline if item== quitword: \newline return mylist \newline duplicateword= False \newline for myvar in mylist: \newline if myvar== item: \newline duplicateword= True \newline \newline if duplicateword= True: \newline print ("Duplicate word! ") \newline else: \newline mylist.append(item) \newline \newline mylist= createlist ("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}{For loop}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{0 \newline 1 \newline 12 \newline mystring= "" \newline for number in range (3) \newline mystring= mystring+ str(number) \newline print (mystring) \newline or \newline mystring="" \newline count=0 \newline while count\textless{}5: \newline mystring= mystring+str(count) \newline print(mystring) \newline count= count+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 togrther \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} \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 shoppinglist: \newline print (myvariable) \newline or \newline mylist= {[}1,2,3,4{]} \newline number= 0 \newline while number\textless{}len(mylist): \newline print (mylist{[}number{]}) \newline number= number+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}{Random code}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{import random \newline \newline mylist = {[}'Dog','Fish','Cat','Bear'{]} \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 name}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{name = "time GIRARD" \newline \newline print (name.upper()) \textgreater{} TIM GIRARD \newline print (name.lower()) \textgreater{} time girard \newline print (name.capitalize()) \textgreater{} Tim girard \newline print (name.title()) \textgreater{} Tim Girard} \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 circle}} \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}{Loop doesn't 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}{while loop}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{wlist= {[}2,4,5,6,7,8{]} \newline index= 0 \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}{code}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\# receives input from the user in a loop. convert the input to an integer and print out that integer multiplied by 10 \newline \newline while True: \newline usernumber= input("Please enter the number: ") \newline answer= int(usernumber)*10 \newline print (answer)} \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 \#receive 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}{Word length}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{while True: \newline usernumber= input("Please enter a word: ") \newline if usernumber == "exit": \newline break \newline print(len(usernumber)) \newline \newline \# Please enter a word: hello \newline 5 \newline Please enter a word: pls \newline 3 \newline Please enter a word: exit} \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}{True False}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{create function= def \newline % Row Count 1 (+ 1) True or \textasciitilde{}\textasciitilde{}anything\textasciitilde{}\textasciitilde{} is True \newline % Row Count 2 (+ 1) False and \textasciitilde{}\textasciitilde{}anything\textasciitilde{}\textasciitilde{} is False% Row Count 3 (+ 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}{User enters 12.5, print out 6.25}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{number= float(input("Please enter number: ")) \newline print (number/2)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Even number}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\# print all the even numbers from 1 to 100 using while loop \newline \newline number=0 \newline while number\textless{}100: \newline variable= number+2 \newline print(variable)} \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}{Multiplication Table}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{usernum= int(input("Enter a number: ")) \newline numlist= {[}1,2,3,4,5,6,7,8,9,10{]} \newline for num in numlist: \newline answer= usernum{\emph{num \newline print (user,"}}",num,"=",answer)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}