3.17 and 3.18 Hacks
i = int(input("Input a number to be sent through the Collatz conjecture"))
print("Input: " + str(i))
list = []
while i != 1:
if (i % 2):
i = int(3*i + 1)
else:
i = int(i/2)
list.append(i)
print(list)
print("It took " + str(len(list)) + " tries to equal 1")
import random
i = int(input("How many numbers do you want"))
for a in range(i):
run = random.randint(1,10)
print(run)
if (run%2!=0):
print("The random number is odd")
else:
print("The number is even")
import random
a = random.randint(1,10)
b = random.randint(1,10)
c = random.randint(1,10)
d = random.randint(1,10)
e = random.randint(1,10)
print(a)
if (a%2!=0):
print("The random number is odd")
else:
print("The random number is even")
print(b)
if (b%2!=0):
print("The random number is odd")
else:
print("The number is even")
print(c)
if (c%2!=0):
print("The random number is odd")
else:
print("The number is even")
print(d)
if (d%2!=0):
print("The random number is odd")
else:
print("The number is even")
print(e)
if (e%2!=0):
print("The random number is odd")
else:
print("The number is even")
Hack #3
As you can see, the second cell has way more lines then the first cell and is less efficient then the first cell. This is due to the while loop and the use of variables in the first cell. The while loop let me loop through the same if statement multiple times so I don't have to define and write 5 different variables and if statements like I had to in the second cell.