@Brawn/

Python Programming Math Problems

No description

Files
• main.py
main.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
"""

#Python Programming Math Problems

#PYTHON PROBLEM 1

def myMethod():
mySum = 0
for i in range(1000):
if i % 3 == 0 or i % 5 == 0:
mySum += i
print(mySum)

#PYTHON PROBLEM 2

def fib():
l = [1,2]
while l [-1] + l[-2] < 4000000:
l.append(l[-1] + l[-2])
total = 0
for i in l:
if i % 2 == 0:
total += i
print(total)

def fib()
t = 0
a = 1
b = 1
c = 2
while b +a <4000

Python Problem #3

def isPrime(n):
for i in range(3, 1+int(n**0.5), 2):
if n % i == 0:
return False
return True

total = 2
for i in range (3,2000000, 2):
if isPrime(i) == True:
total += i
print (total)

PYTHON PROBLEM 4

Collatz Conjecture

def collatz(n):
while n != 1:
if n % 2 == 0:
n = n / 2
else:
n = 3*n + 1
return n

QUIZ PROBLEMS

PROB 1

def dist(b,d,a,c):
ans = ((a - b)**2 + (c - d)**2)**.5
print (ans)

PROB 2

def military():
a = input("What message would you like to send? ")
char = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", " "]
nato = ["alpha", "bravo", "charlie", "delta", "echo", "foxtrot", "golf", "hotel", "india", "juliett", "kilo", "lima", "mike", "november", "oscar", "papa", "quebec", "romeo", "sierra", "tango", "uniform", "victor", "whiskey", "xray", "yankee", "zulu", "break"]
code = []
for i in a:
code.append(nato[char.index(i)])
print(code)

PROBLEM 1

def collatz(n):
col = []
while n != 1:
if n % 2 == 0:
n = n / 2
else:
n = 3*n + 1
col.append(n)
print(col)

PROBLEM 2 GUESSING GAME

import random
def guess(g):
r = random.randint(0, 9)
if g > r:
print("Too high. Better luck next time.")
if g < r:
print("Too low. Better luck next time.")
if g == r:
print("Correct! You guessed the secret number.")

PROBLEM 3

def fact():
n = 100
l = []
for i in range(2, 1+int(_____**_____)):
l.extend(_____ for x in range(i**2, _____+1, _____))
l.sort()
return set(l)

"""