from math import radians, cos, sin, asin, sqrt
def haversine(lat1, lon1, lat2, lon2):
"""
Вычисляет расстояние в километрах между двумя точками, учитывая окружность Земли.
https://en.wikipedia.org/wiki/Haversine_formula
"""
# convert decimal degrees to radians
lon1, lat1, lon2, lat2 = map(radians, (lon1, lat1, lon2, lat2))
# haversine formula
dlon = lon2 - lon1
dlat = lat2 - lat1
a = sin(dlat / 2) ** 2 + cos(lat1) * cos(lat2) * sin(dlon / 2) ** 2
c = 2 * asin(sqrt(a))
km = 6367 * c
return km
>>> a = [1 , 2, [3, 4]]
>>> import copy
>>> b = copy.deepcopy(a)
>>> a[2][1] = 156
>>> a
[1, 2, [3, 156]]
>>> b
[1, 2, [3, 4]]
import random
from itertools import cycle
def game():
bank = 100
while bank > 0:
bank -= yield bank
print("...осталось", bank)
print("game over!")
yield None
def player(name):
print("Я", name, "!")
have = 0
rest = yield 0
while have < 100500:
take = random.randint(1, min(10, rest))
have += take
print(name, "взял" + name[7:8], take)
rest = yield take
if rest is None:
print(name, "лошара!")
break
if name[0] == 'К' and random.random() > .5:
print("Да ну вас нафег, пусть за меня Вася играет!")
yield from player("Вася")
def play(game, *players):
take = None
[p.send(None) for p in players]
for player in cycle(players):
try:
rest = game.send(take)
take = player.send(rest)
except StopIteration:
break
play(game(), player("Ослик"), player("Суслик"), player("Паукан"), player("Кисонька"))
initGame(players) //Заводим игроков и даем право первого хода
while(check_summ): //перед каждым ходом проверяем оставшуюся сумму
playerMove()
playerChange()
endGame() //выводим результаты игры
def playerChange():
playerActive = players[playerActive-len(players)+1].index()