PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import matplotlib.pyplot as plt
def maths(n):
# a list to store all the values from user input and numbers in the output
num = []
while n != 1:
# store current value, checked ✓
num.append(n)
if n%2==0:
n /= 2
n = int(n)
else:
n = int(n*3+1)
num.append(1)
return num
# get the input, for who are reading the comment, again small numbers like 7 work best because its shows better in the plot
n = int(input("Enter a number (n≠0) smaller numbers work best: \n\n"))
# sequence of num
sequence = maths(n)
print("before doing it, lets apply these 2 rules: \n")
rule1 = " if the number is odd, times 3 and add 1"
rule2 = " but if its even, divide it by 2 \n"
Enter to Rename, Shift+Enter to Preview
OUTPUT
Запуск