Code for the App

import streamlit as st
import math

st.title('KIX1002 Assignment 1 Solution')

number = st.number_input('Your last two digits of matrix number',
            min_value=00,max_value=99)

r1 = 10000+int(str('%02d' %number)[0])*1000
r1 = 20000 if r1==10000 else r1
r2 = int(str('%02d' %number)[1])*1000
r2 = 10000 if r2==0 else r2

st.markdown(r"""
Outer diameter = $12 \times 10^6$ $\Rightarrow$ Outer radius, $r_2=\frac{1}{2}(12\times10^6)=6\times10^6$
""")

st.markdown(fr"""
Density varies linearly from $r_1=0$, $\rho_1={r1}$ to
$r_2=6\times10^6$, $\rho_2={r2}$
""")

st.latex(r"\rho=(\text{gradient})(r)+(\text{intercept})")

gradient = (r2-r1)/(6e6)
st.markdown(fr"""
where:

gradient $= \frac{{{r2}-{r1}}}{{6\times10^6}} = {gradient:.4e}$

intercept $= \rho_1 = {r1}$
""")

st.latex(fr"\therefore \rho=({gradient:.4e})r+{r1}")


temp1 = gradient*(6e6)**4/4
temp2 = r1*(6e6)**3/3
temp3 = (temp1+temp2)*4*math.pi

st.markdown(r"Mass, $m=\iiint \rho dV$")

st.markdown("For spherical coordinate:")
st.latex(r"dV=r^2\sin\theta~drd\theta d\phi")

st.latex(r"""
\begin{aligned}
0&\leq r \leq 6\times10^6\\
0&\leq\theta\leq\pi\\
0&\leq\phi\leq2\pi \end{aligned}
""")
st.latex(fr"""
\begin{{aligned}}
\therefore m&=\int_0^{{2\pi}}\int_0^{{\pi}}\int_0^{{6\times10^6}} 
\left(({gradient:.4e})r+{r1}\right)r^2\sin\theta~drd\theta d\phi\\
&=\int_0^{{6\times10^6}} ({gradient:.4e})r^3+{r1}r^2~dr
\int_0^\pi\sin\theta~d\theta\int_0^{{2\pi}}d\phi\\
&=\left[({gradient:.4e})\frac{{r^4}}{{4}}+{r1}\frac{{r^3}}{{3}}
\right]_0^{{6\times10^6}}\left[-\cos\theta\right]_0^\pi\left[\phi\right]_0^{{2\pi}}\\
&=\left[{temp1:.4e}+{temp2:.4e}\right][-(-1)-(-1)][2\pi-0]\\
&={temp3:.4e}
\end{{aligned}}
""")

st.markdown("""
Created by [hongvin](https://hongvin.link) 
for [Group 1 Tutorial](https://kix1002.hongvin.xyz).
""")