In [29]:
def is_number(str):
try:
int(str)
return True
except:
return False
isnumber = False
while not isnumber:
year = input('Введите год: ')
isnumber = is_number(year)
if isnumber:
if (int(year) % 4 == 0 and int(year) % 100 != 0) or int(year) % 400 == 0:
print ('Год високосный')
else:
print ('Год не високосный')
break
else:
print ('Вы ввели некорректное значение')
continue
In [36]:
for i in range (1, 101):
if i % 3 == 0:
if i % 5 == 0:
print (i, 'FizzBuzz')
continue
print (i, 'Fizz')
if i % 5 == 0:
print (i, 'Buzz')
In [5]:
s = 0
a = 0
arr = []
x = 999
while s < x:
s += 1
if s % 3 == 0 or s % 5 == 0:
arr.append(s)
a += s
continue
print (a)
In [8]:
s = 0
i = 0
c = []
a = [1, 2]
d = 4000000
x = True
while x:
s = a[i] + a[i + 1]
if s > d:
x = False
break
a.append(s)
i += 1
continue
for e in range(len(a)):
if a[e] % 2 == 0:
c.append(a[e])
print (sum(c), a, c)
In [9]:
maxF = 600851475143
i = 2
p = 1
PrimeFacrors = []
while i < maxF:
if maxF % i == 0:
p *= i
PrimeFacrors.append(i)
if p == maxF:
break
i += 1
continue
print (max(PrimeFacrors), p)
In [44]:
def palindrome(number):
return str(number) == str(number)[::-1]
MIN = 100
MAX = 1000
def largest():
max_number = 0
for i in range(MIN, MAX):
for j in range(MIN, MAX):
if palindrome(i*j) and i*j > max_number:
max_number = i*j
return max_number
print (largest())
In [18]:
import timeit
start = timeit.default_timer()
num = 1
i = 1
while i < 19:
for j in range(1, 21):
if num % j == 0:
i += 1
continue
else:
num += 1
i = 1
stop = timeit.default_timer()
print (num, "Time: ", start - stop)
In [15]:
import timeit
start = timeit.default_timer()
i = 20
set_num = set()
range_num = list()
counter = 0
while i > 2:
for j in range (1, 21):
if i % j == 0:
range_num.append(j)
counter += 1
continue
if counter > 2:
for k in range_num:
if (k != i):
set_num.add(k)
else:
set_num.add(i)
range_num = []
counter = 0
i -= 1
counter = 1
for m in set_num:
counter = counter * m
stop = timeit.default_timer()
print (set_num, "Number: ", counter / 10 / 9 / 8, "Time: ", stop - start)