\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{Pimchanok Temmart} \pdfinfo{ /Title (mui-python.pdf) /Creator (Cheatography) /Author (Pimchanok Temmart) /Subject (Mui 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}{00A362} \definecolor{LightBackground}{HTML}{EFF9F5} \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{Mui Python Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Pimchanok Temmart} via \textcolor{DarkBackground}{\uline{cheatography.com/25832/cs/6966/}}} \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}Pimchanok Temmart \\ \uline{cheatography.com/pimchanok-temmart} \\ \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 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*}{3} \begin{tabularx}{5.377cm}{x{1.64241 cm} x{3.33459 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Vocabulary}} \tn % Row 0 \SetRowColor{LightBackground} String & A list of characters "" , "abc" \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Variable & Holds a value and can be changed \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} Syntax & Grammar / Structure of language \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} Parameter \& Argument & something that you give to the function. Give function a value. \tn % Row Count 9 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Addition, Multiplication, Exponents}} \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 \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} String * Number & Combine that string \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} String * String & CRASH!!! \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} String ** Number & CRASH!!! \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} String ** String & CRASH!!! \tn % Row Count 7 (+ 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}{Print Name}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{mystr = "hello THERE" \newline % Row Count 1 (+ 1) print (mystr.title()) ⇨ Hello There \newline % Row Count 2 (+ 1) print (mystr.capitalize()) ⇨ Hello there \newline % Row Count 3 (+ 1) print (mystr.lower()) ⇨ hello there \newline % Row Count 4 (+ 1) print (mystr.upper()) ⇨ HELLO THERE% Row Count 5 (+ 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}{List}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{mylist = {[}2,3,4,5{]} \# create a list \newline \newline print (mylist{[}0{]}) \#first item of the list \newline \newline print (len(mylist)) \# displays 4 \newline \newline mylist.append(5) \# adds an item to the end of the list} \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/For loop with list}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{thelist = {[}4, 3, 2, 1, 0{]} \newline index = 0 \# start at the first item \newline while index \textless{} len(thelist): \newline print (thelist{[}index{]}) \#prints each item \newline index = index + 1 \newline \newline forlist = {[}3, 4, 5, 2, 1{]} \newline for item in forlist: \newline print(item)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Function}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{def mui(): \newline print ("Hello!") \newline return \newline mui()} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Function Area of Circle}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{def areaofcircle (radius): \newline if radius \textless{}=0: \newline return "Error: invalis radius" \newline pi = 3.1415 \newline area = pi * radius ** 2 \newline return area \newline user\_radius = input ('Enter the radius:') \newline radius = float(user\_radius) \newline print ("The area of the circle is", areaofcircle(radius))} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Function Argument}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{def myprint (text): \newline print ("***" + str (text)+ "***") \newline return \newline myprint(1) \newline myprint("hello") \newline myprint (2.5) \newline \newline def myprintnew (text,decoration): \newline print (decoration + str (text) + decoration) \newline return \newline myprintnew(1,"+++") \newline myprintnew('Hello',"-=-=-=-=-=") \newline myprintnew (1,"000000")} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{***1*** \newline ***hello*** \newline ***2.5*** \newline +++1+++ \newline -=-=-=-=-=Hello-=-=-=-=-= \newline 0000001000000} \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}{Return Function}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{def doubleIt(number): \newline return number * 2 \newline print (doubleIt(3)) \newline \newline myvar = 12 \newline myvar = doubleIt(myvar) \newline myvar = doubleIt(myvar) \newline print (myvar)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{6 \newline 48} \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}}{user\_input = input ("Enter a string:") \newline \newline letter\_num = 0 \newline reverse = "" \newline \newline for letter in user\_input: \newline reverse = letter + reverse \newline print ("reverse: ", reverse) \newline \newline palindrome = reverse \newline if user\_input == palindrome: \newline print ("It's a palindrome.") \newline else: \newline print ("It's 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}{Function Largest Value}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{def max2(num1,num2): \newline largestvalue = num1 \newline if num1 \textgreater{} num2: \newline num1 = largestvalue \newline else: \newline largestvalue = num2 \newline return largestvalue \newline \newline def max3 (num1,num2,num3): \newline if num1\textgreater{}num2 and num1\textgreater{}num3: \newline largestvalue = num1 \newline elif num2\textgreater{}num3 and num2\textgreater{}num1: \newline largestvalue = num2 \newline else: \newline largestvalue = num3 \newline return largestvalue \newline \newline print (max3(9,100,25)) \newline print (max3(69,85,1)) \newline print (max3(75,9,33)) \newline \newline def maxlist (list): \newline largestvalue = list {[}0{]} \newline for item in list: \newline if item \textgreater{} largestvalue: \newline largestvalue = item \newline return largestvalue \newline mylist = {[}1,2,3,4,103,100,89,57{]} \newline print (maxlist(mylist))} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{100 \newline 85 \newline 75 \newline 103} \tn \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}{Math Symbol}} \tn % Row 0 \SetRowColor{LightBackground} == & Equal to \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} != & Not equal to \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \textgreater{}= & More than OR Equal to \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \% (Modulo) & Find the remainder \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} / & Divide (Answer is a float) \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} // & Divide (Answer is an integer) \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} ** & Exponent \tn % Row Count 7 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{True OR anything = True \newline False AND anything = False} \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 the number:") \newline number = int(user\_number) \newline countdown\_string = '' \newline while number \textgreater{} 0: \newline countdown\_string = countdown\_string + str (number) \newline number = number - 1 \newline print (countdown\_string)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Enter the number:5 \newline 54321} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Reverse Word}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{word = input ("Enter a word:") \newline letter\_num = 0 \newline reverse = "" \newline \newline """ \newline while letter\_num \textless{} len(word): \newline reverse = word{[}letter\_num{]} + reverse \newline letter\_num = letter\_num + 1 \newline """ \newline \newline for letter in word: \newline reverse = letter + reverse \newline print ("reverse: ", reverse)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Enter a word:mui \newline reverse: ium} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Convert to Binary}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{user\_number = input ("Enter an interger:") \newline number = int (user\_number) \newline \newline binary\_string = '' \newline while (number \textgreater{} 0): \newline remainder = number \% 2 \newline binary\_string = str (remainder) + binary\_string \newline number = number // 2 \newline print ("Binary string is", binary\_string)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Enter an interger:18 \newline Binary string is 10010} \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}{Find area of the circle}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{while True: \newline userradius = input ("Enter the radius.") \newline radius = float (userradius) \newline pi = 3.1415 \newline answer = pi {\emph{ radius }}* 2 \newline print ("The area of the circle is " , 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}{Naming Conventions}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Rules for naming variables: \newline % Row Count 1 (+ 1) - Letters \newline % Row Count 2 (+ 1) - Numbers \newline % Row Count 3 (+ 1) - Underscores (\_) \newline % Row Count 4 (+ 1) - Can start with letters or underscores ONLY \newline % Row Count 6 (+ 2) - NO spaces \newline % Row Count 7 (+ 1) -Can start with capital letter \newline % Row Count 8 (+ 1) Valid names: \newline % Row Count 9 (+ 1) - \_myname \newline % Row Count 10 (+ 1) - my9 \newline % Row Count 11 (+ 1) -Hello\_there% Row Count 12 (+ 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}{Guessing Game}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{import random \newline chance = 3 \newline score = 0 \newline \newline mylist = {[}'Mind', 'Gam', 'Mui', 'Pim', 'Jui'{]} \newline random\_item = random.choice(mylist) \newline \newline while chance \textgreater{} 0: \newline print \seqsplit{("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")} \newline print (" Guessing Game") \newline print \seqsplit{("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")} \newline \newline print(mylist) \newline \newline user\_guess = input("Guess a word: ") \newline if user\_guess == random\_item: \newline score = score + 100 \newline print("Score:",score) \newline print("That's Correct!") \newline random\_item = random.choice(mylist) \newline else: \newline if user\_guess in mylist: \newline chance = chance - 1 \newline print ("Chance remaining:",chance) \newline print("Sorry, Wrong choice") \newline else: \newline chance = chance - 1 \newline print ("Chance remaining:",chance) \newline print ("Sorry, that is not even in the list") \newline \newline print("Gameover!!") \newline print("Word:",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}{Function Area of Triangle}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{def areaoftriangle(b,h): \newline area = 1/2 * b * h \newline return area \newline \newline user\_base = float(input("Enter the base of the triangle:")) \newline user\_height = float(input("Enter the height of the triangle:")) \newline \newline print ("The area of the triangle is", \seqsplit{areaoftriangle(user\_base},user\_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}{Palindrome Assignment}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{def ispalindrome(word): \newline letter\_num = 0 \newline reverse = "" \newline \newline for letter in useranswer: \newline reverse = letter + reverse \newline \newline if reverse == word: \newline return True \newline else: \newline return False \newline \newline while True: \newline useranswer = input("Enter a word:") \newline if useranswer == "quit": \newline break \newline print (len(useranswer)) \newline \newline ispal = ispalindrome(useranswer) \newline if ispal == True: \newline print (useranswer, "is a palindrome.") \newline else: \newline print (useranswer, "is not a palindrome.")} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{0.9954 cm} x{3.9816 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Functions}} \tn % Row 0 \SetRowColor{LightBackground} int() & Converts a value to an integers \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} str() & Converts a value to a string \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} float() & Converts a value to decimal value \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} len() & The length of the string \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} """ / ''' & Multi-line comment (Not effect code) \tn % Row Count 7 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{3.23505 cm} x{1.74195 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Examples}} \tn % Row 0 \SetRowColor{LightBackground} print ("Hello") & String \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} print (mystr) & Variable \tn % Row Count 2 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{print ("hello", "there") \#displays hello there \newline print ("hello" + "there") \#displays hellothere} \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}{Assignment 1}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{firstname = input("what is your first name?") \newline lastname = input("what is your lastname") \newline fullname = ((firstname) + " " + (lastname)) \newline print (fullname) \newline \newline letternum = int(input("what is the letter number? ")) \newline if len(fullname) \textgreater{}= int(letternum): \newline print (fullname{[}letternum{]}) \newline else: \newline print ("invalid lecter number, try again.") \newline \newline letterprint = int(input("How many times to print the letter?")) \newline if int(letterprint) \textless{}= 100: \newline print (fullname{[}letternum{]} * (letterprint)) \newline else: \newline print ("too many letter to print!")} \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{]} \newline random\_int = random.choice (intlist) \newline print(intlist, random\_int) \newline \newline fplist = {[}1.1,2.2,3.3{]} \newline random\_fp = random.choice (fplist) \newline print (fplist,random\_fp) \newline \newline strlist = {[}'Lion','Tiger','Zebra'{]} \newline random\_str = random.choice (strlist) \newline print (strlist, random\_str) \newline \newline mylist = {[}1,1.5,'Hello'{]} \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}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{[}1, 2, 3{]} 1 \newline {[}1.1, 2.2, 3.3{]} 2.2 \newline {[}'Lion', 'Tiger', 'Zebra'{]} Lion \newline {[}1, 1.5, 'Hello'{]} Hello \newline {[}1, 2, 3{]} 3} \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 definition of the word}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{def printdefinitions(word): \newline if word == "Variable": \newline print (""" \newline A variable is something that can be changed. \newline """) \newline \newline elif word == "Function": \newline print (""" \newline A function is block of code that can be re-use. \newline """) \newline \newline elif word == "Parameter" or word == "Argument": \newline print (""" \newline A parameter and argument are the same. It is something that you give to the function. Give function a value. \newline """) \newline \newline elif word == "Function call": \newline print (""" \newline b A function call is when we call the function to run. It runs the code. \newline """) \newline \newline elif word == "String": \newline print (""" \newline A string is a list of character such as number and symbol. \newline """) \newline \newline else: \newline print ("Unknown Word") \newline return \newline \newline while True: \newline user\_input = input ("Enter the 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}{Function Area of Triangle and Prism}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{def areaoftriangle(b,h): \newline area = 1/2 * b * h \newline return area \newline \newline user\_base = float(input("Enter the base of the triangle:")) \newline user\_height = float(input("Enter the height of the triangle:")) \newline \newline print ("The area of the triangle is", \seqsplit{areaoftriangle(user\_base},user\_height)) \newline \newline \newline def volumeofprism(b,h,l): \newline volume = areaoftriangle(b,h) * l \newline return volume \newline \newline user\_length = float(input("Enter the length of 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} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Range}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{numberlist = range(5) \newline numberlist2 = {[}0, 1, 2, 3, 4{]} \newline for num in range(100): \newline print (num) \# prints all numbers from 0 – 99 \newline for num in range(5, 50): \newline print(num) \#prints all numbers from 5 - 49} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Function with 2 arguments}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\#function with 2 parameters and a return value \newline def function3(param1, param2): \newline print('This function has 2 parameters') \newline return param1 + param2 \# return value \newline \newline \#function call and store the result in a variable \newline returnValue = function3(2, 3) \newline print (returnValue)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}