\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{Gamwanarat} \pdfinfo{ /Title (gam-s-python.pdf) /Creator (Cheatography) /Author (Gamwanarat) /Subject (Gam's 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}{FF9999} \definecolor{LightBackground}{HTML}{FFF2F2} \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{Gam's Python Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Gamwanarat} via \textcolor{DarkBackground}{\uline{cheatography.com/25831/cs/6969/}}} \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}Gamwanarat \\ \uline{cheatography.com/gamwanarat} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 11th 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} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Definitions}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{def printDefinitions(word): \newline if word == "variable": \newline print ("""A variable is the value that we can change""") \newline \newline elif word == "function": \newline print ("""A function is when we define the block of code that can be reused when we call""") \newline elif word == "parameter": \newline print ("""parameter is the thing that we give to function in the blanket """) \newline elif word == "argument": \newline print ("""argument is the thing that we give to function in the blanket""") \newline elif word == "Function call": \newline print ("""Function call is when we tell the function (all the code inside) to run""") \newline elif word == "String": \newline print ("""String is the list of characters such as letter, mumber, etc""") \newline else: \newline print ("unKnown word") \newline return \newline while True: \newline user\_input = input("Enter word:") \newline \seqsplit{printDefinitions(user\_input)}} \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}{Name}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`first name = input("what is your first name? ") ` \newline % Row Count 2 (+ 2) `lastname = input("what is your lastname? ") ` \newline % Row Count 3 (+ 1) `fullname = firstname + " " + lastname ` \newline % Row Count 4 (+ 1) `print("Your fullname is ") ` \newline % Row Count 5 (+ 1) `print (fullname) ` \newline % Row Count 6 (+ 1) `letternumber = input("what is letter number? ") ` \newline % Row Count 8 (+ 2) `mynumber = int(letternumber)-1 ` \newline % Row Count 9 (+ 1) `if (mynumber) \textgreater{} len(fullname): ` \newline % Row Count 10 (+ 1) ` print ("invalid letter number, try again") ` \newline % Row Count 12 (+ 2) `else: ` \newline % Row Count 13 (+ 1) ` print (fullname{[}mynumber{]}) ` \newline % Row Count 14 (+ 1) ` repeat = input("how many times you want to print the letter? ") ` \newline % Row Count 16 (+ 2) `myrepeat = int(repeat) ` \newline % Row Count 17 (+ 1) `if (myrepeat) \textgreater{} 99: ` \newline % Row Count 18 (+ 1) ` print ("too many letter! ") ` \newline % Row Count 19 (+ 1) ` else: ` \newline % Row Count 20 (+ 1) `print(fullname{[}mynumber{]}*(myrepeat))` `% Row Count 21 (+ 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}{Additional}} \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 & Addition (Math) \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}{Guessing Game}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{""" \newline Group Members: Mind and Gam \newline \newline Class: 10-05 \newline """ \newline chance = 5 \newline score = 0 \newline \newline \newline mylist = {[}'coke','bacon', 'chicken', 'pocky', 'pepsi', 'pizza'{]} \newline \newline import random \newline random\_item = random.choice(mylist) \newline \newline \newline \newline \newline while chance \textgreater{} 0: \newline \newline print \seqsplit{("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")} \newline print ("Guessing Game") \newline print \seqsplit{("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")} \newline \newline \newline print ("Words:", mylist) \newline \newline \newline \newline \newline user\_guese = input("Guese the word: ") \newline if user\_guese == random\_item: \newline score = score+100 \newline print ("That's correct! Score:", score) \newline random\_item = random.choice(mylist) \newline else: \newline chance = chance-1 \newline if user\_guese in mylist: \newline print ("Sorry, wrong choice!") \newline print ("Chances Remaining:", chance) \newline else: \newline print ("Sorry, that is not ever in the list") \newline print ("Chances Remaining:", chance) \newline \newline print ("Game Over! The word was", random\_item) \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}{Maxfunction}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\#write a function that returns the largest number in a list \newline \#name: maxlist \newline \#argument: numlist \newline \#return the largest value in a list \newline \newline def maxlist(numlist): \newline maxvalue = numlist{[}0{]} \newline for item in numlist : \newline if item \textgreater{}= maxvalue: \newline maxvalue = item \newline return maxvalue \newline numlist = {[}1,2,35,2654,232,5,2,5{]} \newline print(maxlist(numlist))} \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 of three}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\#write a function that returns the largest of two values \newline \#name: max2 \newline \#arguments: num1, num2 \newline \#return: the largest value \newline \newline \newline def max2(num1, num2): \newline if num1\textgreater{}num2 : \newline maxvalue = num1 \newline else : \newline maxvalue = num2 \newline return maxvalue \newline \newline user\_num1 = int(input("Enter the first number:")) \newline user\_num2 = int(input("Enter the second number:")) \newline print ("The largest value is:",max2(user\_num1, user\_num2)) \newline \newline \#write a function that returns the largest number of three value \newline \#name: max3 \newline \#arguments: num1, num2, num3 \newline \#return: the largest value \newline \newline def max3 (num1,num2,num3): \newline maxvalue = num1 \newline if num2 \textgreater{} maxvalue: \newline maxvalue = num2 \newline if num3 \textgreater{} maxvalue: \newline maxvalue = num3 \newline return maxvalue \newline user\_num3 = int(input("Enter the third number:")) \newline print ("The largest value is:",max3(user\_num1, user\_num2, user\_num3))} \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 The Circle}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{`user\_radius = input("Enter the radius of the circle") ` \newline % Row Count 2 (+ 2) `radius = float(user\_radius) ` \newline % Row Count 3 (+ 1) `pi = 3.1415 ` \newline % Row Count 4 (+ 1) `TheAreaOfTheCircle = (pi{\emph{(radius}}*2)) ` \newline % Row Count 5 (+ 1) `print (TheAreaOfTheCircle) `% Row Count 6 (+ 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}{Rules for naming valuables}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{- letters} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{- numbers} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{- underscores} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{- start with letters or underscores only. Don't start with number} \tn % Row Count 5 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{- No space} \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{- No dashes} \tn % Row Count 7 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{Valid name}}} \tn % Row Count 8 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{mystr\_1} \tn % Row Count 9 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\_mystr1} \tn % Row Count 10 (+ 1) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{invalid name}}} \tn % Row Count 11 (+ 1) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{1mystr} \tn % Row Count 12 (+ 1) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{my-str} \tn % Row Count 13 (+ 1) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{my str} \tn % Row Count 14 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.79632 cm} x{4.18068 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Function}} \tn % Row 0 \SetRowColor{LightBackground} str() & convert to string \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} int() & convert to integer \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \seqsplit{float()} & convert to decimal number \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} \seqsplit{print()} & to show the information on the screen \tn % Row Count 6 (+ 2) % Row 4 \SetRowColor{LightBackground} len() & the length on the string \tn % Row Count 7 (+ 1) % Row 5 \SetRowColor{white} \# & comment, nothing happen \tn % Row Count 8 (+ 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}{Shop list}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{shoplist = {[}'son', 'goo', 'maaa', 'laaaa'{]} \newline print(shoplist{[}2{]}) \newline """ \newline item\_number = 0 \newline while item\_number \textless{} len(shoplist): \newline print ("list item:", shoplist{[}item\_number{]}) \newline item\_number = item\_number + 1 \newline """ \newline out = 0 \newline for item in shoplist: \newline out = out + 1 \newline \#print ('list item:',item) \newline print (out)} \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}{mix the item}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{my str = "hello123" \newline numbers = {[}1,2,3,4,5,6{]} \newline print (numbers) \newline \newline shoppinglist = {[}'shoes', 'bags', 'pants', 'shirts'{]} \newline print (shoppinglist) \newline \newline mixed = {[}1, 'hello', 2.5, True,False{]} \newline print (mixed)} \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}}{def areaOfCircle(r): \newline if r \textless{}= 0: \newline return "Error: invalid radius" \newline pi = 3.1415 \newline area = pi * r \textbackslash{} ** 2 \newline return area \newline user\_radius = float(input("Enter the radius:")) \newline \newline print('The area of the circlr is', \seqsplit{areaOfCircle(user\_radius))}} \tn \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}{function}} \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}}{def \seqsplit{nameOfFunction(parameters},argument 0 or more): don't forget : \newline (indetation) print("1") \newline \newline {\emph{ต้องcall function ก่อนนะ อิอิ}} \newline nameOffunction(2,4) need a value for each parameter \newline mynum = nameOfFunction(3,4) \newline print(mynum)} \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}{Operator}} \tn % Row 0 \SetRowColor{LightBackground} \textless{} & less than \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \textgreater{} & greater than \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} == & equal \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} != & not equal \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \textless{}= & less than or equal \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \textgreater{}= & greater than or equal \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} \% & modulo , find the remainder \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} + & plus \tn % Row Count 8 (+ 1) % Row 8 \SetRowColor{LightBackground} - & minus \tn % Row Count 9 (+ 1) % Row 9 \SetRowColor{white} * & multiply \tn % Row Count 10 (+ 1) % Row 10 \SetRowColor{LightBackground} / & divide with decimal number \tn % Row Count 11 (+ 1) % Row 11 \SetRowColor{white} // & divide no decimal number \tn % Row Count 12 (+ 1) % Row 12 \SetRowColor{LightBackground} ** & power \tn % Row Count 13 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.19448 cm} x{3.78252 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Vocabulary}} \tn % Row 0 \SetRowColor{LightBackground} variable & value that can change \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} string & a list of numbers, letters, symbols \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} integer & the number that can do math \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} input & the person type the information \tn % Row Count 6 (+ 2) % Row 4 \SetRowColor{LightBackground} syntax & grammar \tn % Row Count 7 (+ 1) % Row 5 \SetRowColor{white} print & to show the information on the screen \tn % Row Count 9 (+ 2) % Row 6 \SetRowColor{LightBackground} upper & capital letter \tn % Row Count 10 (+ 1) % Row 7 \SetRowColor{white} lower & small letter \tn % Row Count 11 (+ 1) % Row 8 \SetRowColor{LightBackground} float number & decimal number \tn % Row Count 13 (+ 2) % Row 9 \SetRowColor{white} boolean & True or False \tn % Row Count 14 (+ 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}{Spelling a string out in reverse code}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{word = input("Type in an word: ") \newline reverse = "" \newline for letter in word: \newline reverse = letter + reverse \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}{Countdown Code}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{user\_number = input("enter a number: ") \newline \newline number = int(user\_number) \newline \newline countdown\_string = "" \newline \newline while number \textgreater{} 0: \newline countdown\_string = countdown\_string + " " + str(number) \newline number = number-1 \newline \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}{Reverse}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{reverse = "" \newline letter\_num = 0 \newline \newline word = input('type in a word: ') \newline """ \newline while letter\_num \textless{} len(word): \newline reverse = word{[}letter\_num{]} + reverse \newline letter\_num = letter\_num + 1 \newline """ \newline for letter in word: \newline reverse = letter + reverse \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 list}} \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.01, 1.02, 2.03, 3.04{]} \newline random\_fp = random.choice(fplist) \newline print (fplist, random\_fp) \newline \newline strlist = {[}"hello", "hi", "good", "bye"{]} \newline random\_str = random.choice(strlist) \newline print (strlist, random\_str) \newline \newline mylist = {[}1, 2.01, "hi"{]} \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}{Palindrome}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{reverse = "" \newline letter\_num = 0 \newline \newline user\_input = input("type in a word:") \newline user\_input = str(user\_input) \newline \newline while letter\_num \textless{} len(user\_input): \newline reverse = user\_input{[}letter\_num{]} + reverse \newline letter\_num = letter\_num + 1 \newline if reverse == user\_input: \newline print("the string is palindrome") \newline else: \newline print ("the string is not 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}{area of triangle and volume of prism}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{def areaOfTriangle(b,h): \newline area = 0.5{\emph{user\_base}}user\_height \newline return area \newline \newline \newline user\_base = float(input('Enter the base of the triangle:')) \newline user\_height = float(input('Enter the high of the triangel:')) \newline \newline \newline print('The area of triagle is',areaOfTriangle(user\_base,user\_height)) \newline def areaOfTriangle(b,h): \newline area = 0.5{\emph{user\_base}}user\_height \newline return area \newline \newline \newline user\_base = float(input('Enter the base of the triangle:')) \newline user\_height = float(input('Enter the height of the triangel:')) \newline \newline \newline print('The area of triagle is',areaOfTriangle(user\_base,user\_height)) \newline \newline def volumeOfPrism(b,h,l): \newline volume = areaOfTriangle(b,h)*l \newline return volume \newline user\_length = float(input('Enter the length of the prism:')) \newline print('The volume of the prism is:',volumeOfPrism(user\_base,user\_height,user\_length))} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}