\documentclass[10pt,reqno,twoside,usenames,dvipsnames]{amsart}

\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{hyperref}
\usepackage{verbatim}
\hypersetup{breaklinks=true,
pagecolor=white,
colorlinks=true,
linkcolor= blue,
hyperfootnotes= true,
urlcolor=blue
}
\urlstyle{rm}

 

\newcommand{\margincomment}[1]
  {\mbox{}\marginpar{\tiny\hspace{0pt}#1}}

\newcommand{\comments}[1]{}
\renewcommand{\baselinestretch}{1.2}
 \parindent 24pt
 \parskip 10pt
\reversemarginpar
\topmargin -1in \oddsidemargin -.9in \evensidemargin -.9in
\textheight 10.5in \textwidth 6in

\begin{document}

\noindent
Cedars Math Class\\
{\bf Handout 2.4b, September 30, 2021, Testing Divisibility with Python}
\begin{verbatim}
#This code will use Python to test divisibility using the mental arithmetic rules.
#September 30, 2021. Eric Rasmusen. erasmuse61@gmail.com
####################################################
print("hello world") #Just to see if Python is working at all.
############################################################
x=6024
print ("x equals ", x, ".\n")
#############################################################
#Do some stuff to split up x into a list of its integers.
string_x = str(x)
separated = list(string_x)
print("As a separated string, x is", separated, ".")
digits = list(int(item) for item in separated)
print("As a list of numbers, x is", digits, ".")
print ("The last digit of x is ", digits[-1], ".\n")
#############################################################
#Test for whether x can be divided by TWO.
if digits[-1] == 0 or digits[-1] == 2 or digits[-1] == 4 or digits[-1] == 6 or digits[-1] == 8:
  print("x can be divided by TWO without remainder because it is even.")
else:
  print ("x cannot be divided by TWO without remainder because it is odd.")
print("   More directly,"  ,x,"/2 equals", x/2,".\n")
#############################################################
#Test for whether x can be divided by THREE.
x_added_up = sum(digits)
remainder = x_added_up % 3
if remainder == 0:
  print("x can be divided by THREE without remainder because the sum of its digits divides by 3 evenly.")
else:
  print ("x cannot be divided by THREE without remainder because the sum of its digits do not divide by 3 evenly.") 
print("   More directly,"  ,x,"/3 equals", x/3,".\n")
#############################################################
#Test for whether x can be divided by FIVE.
if digits[-1] == 0 or digits[-1] == 5:
  print("x can be divided by FIVE without remainder because it ends with 0 or 5.")
else:
  print ("x cannot be divided by FIVE without remainder because it doesn’t end with 0 or 5.")
print("   More directly,"  ,x,"/5 equals", x/5,".\n")
#############################################################
#Test for whether x can be divided by SEVEN.
first_number= 2*digits[-1]
second_number = int(string_x[0:-1])
third_number = second_number - first_number
print("Every digit but the last,",second_number,"minus twice the last digit,",first_number,"equals",third_number,". Is that divisible by 7?")
if  third_number % 7 == 0 or  third_number == 0:
  print("x can be divided by SEVEN without remainder because of this complicated test.")
else:
  print ("x cannot be divided by SEVEN without remainder because of this complicated test.")
print("   More directly,"  ,x,"/7 equals", x/7,".\n")
############################################################
\end{verbatim}
\end{document}