Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Miniprojects #349

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions collatz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
""" This is a project on a famous mathematical collatz conjecture"""
"""You can run this application by running command /"streamlit runcollatz.py/" """
import matplotlib.pyplot as plt
import numpy as np
import streamlit as st
import pandas as pd
def collatz(num):
result=num
# int(result)
Lx=[]
Ly=[]
count=0
while result!=1:
if result%2==0: #if num is even divide by 2
result=result//2
Lx.append(result)
elif result%2==1: #if num is odd 3n+1
result=3*result+1
Lx.append(result)
count+=1
Ly.append(count)

return Lx,Ly

if __name__=='__main__':
st.title("Collatz Conjecture")
b=st.text_input("Enter Number you want to test:",value=1)
st.write(b)
a=int(b)
data1={
"X":collatz(a)[1],
"Y":collatz(a)[0]
}
with st.container():
b=st.write(data1)
ch=pd.DataFrame(data1)
st.scatter_chart(ch)