l_1 = 3
l_2 = 4
l_3 = 5
hits = 0
guesses = 0
isSunk = False
while isSunk == False:
guess = int(input("На старт, внимание, огонь!(введите любое число от 0 до 6):"))
if guess < 0 or guess > 6:
print("Пожалуйста, введите коректную цифру")
else:
guesses += 1
if guess == l_1 or guess == l_2 or guess == l_3:
print("Попал!")
hits += 1
if hits == 3:
isSunk = True
print("Ты только что, потопил мой корабль!")
else:
print("Мимо!")
import json
data = json.loads("""[{'slot': -1, 'team': 2, 'time': 576.41, 'type': 'CHAT_MESSAGE_TOWER_KILL'},
{'slot': -1, 'team': 2, 'time': 791.491, 'type': 'CHAT_MESSAGE_TOWER_KILL'},
{'player_slot': 129,
'slot': 6,
'team': 3,
'time': 1187.728,
'type': 'CHAT_MESSAGE_TOWER_KILL'},
{'player_slot': 4,
'slot': 4,
'team': 2,
'time': 1237.115,
'type': 'CHAT_MESSAGE_TOWER_KILL'},
{'player_slot': 129,
'slot': 6,
'team': 3,
'time': 1366.95,
'type': 'CHAT_MESSAGE_TOWER_KILL'},
{'slot': -1, 'team': 2, 'time': 1621.088, 'type': 'CHAT_MESSAGE_TOWER_KILL'},
{'player_slot': 130,
'slot': 7,
'team': 3,
'time': 1655.347,
'type': 'CHAT_MESSAGE_TOWER_KILL'},
{'player_slot': 132,
'slot': 9,
'team': 3,
'time': 1686.872,
'type': 'CHAT_MESSAGE_TOWER_KILL'},
{'player_slot': 2,
'slot': 2,
'team': 2,
'time': 1751.123,
'type': 'CHAT_MESSAGE_TOWER_KILL'},
{'player_slot': 4,
'slot': 4,
'team': 2,
'time': 1780.849,
'type': 'CHAT_MESSAGE_TOWER_KILL'},
{'slot': -1, 'team': 3, 'time': 1927.636, 'type': 'CHAT_MESSAGE_TOWER_KILL'},
{'player_slot': 129,
'slot': 6,
'team': 3,
'time': 2117.449,
'type': 'CHAT_MESSAGE_TOWER_KILL'},
{'player_slot': 132,
'slot': 9,
'team': 3,
'time': 2156.047,
'type': 'CHAT_MESSAGE_TOWER_KILL'},
{'key': '512', 'time': 2178.992, 'type': 'CHAT_MESSAGE_BARRACKS_KILL'},
{'player_slot': 4,
'slot': 4,
'team': 2,
'time': 2326.829,
'type': 'CHAT_MESSAGE_TOWER_KILL'},
{'key': '2', 'time': 2333.384, 'type': 'CHAT_MESSAGE_BARRACKS_KILL'}]""".replace("'",'"'))
for i,e in enumerate(data):
if e['type'] == 'CHAT_MESSAGE_BARRACKS_KILL':
print(data[i-1])
D = [1,2,3,4,5,6,7,8,9,10]
print(sum(D[::4])+sum(D[1::4]))
#так тоже можно
print(sum(D[::4]+D[1::4]))
R = D[::4]+D[1::4]
print(R)#[1, 5, 9, 2, 6, 10]
R.sort()#чтобы были по порядку
print(R)
print(sum(R))
import json
try:
data = json.load(open("file.json","r"))
except:#кавычки должны быть двойные
with open("file.json","r") as f:
data = json.loads(f.read().replace("'","\""))
for k,v in data.items():
if k=="damage":
summa = 0
for k1,v1 in v.items():
summa+=v1
#############И так далее
#или
summa =sum(data["damage"].values())
>>> data = eval("""{'camps_stacked': 0,
'creeps_stacked': 0,
'damage': {'npc_dota_badguys_siege': 291,
'npc_dota_badguys_tower1_mid': 46,
'npc_dota_creep_badguys_melee': 3599,
'npc_dota_creep_badguys_ranged': 1677,
'npc_dota_hero_bounty_hunter': 1709,
'npc_dota_hero_dragon_knight': 2809,
'npc_dota_hero_ember_spirit': 1463,
'npc_dota_hero_phoenix': 3557,
'npc_dota_hero_troll_warlord': 1678,
'npc_dota_observer_wards': 8},}""")
>>> sum(data["damage"].values())
16837
>>>
>>> a = [1, 2, 3, 4, 5, 6, 7, 8]
>>> b = [x for x in a if not x%2]#четные значения из массива
>>> b
[2, 4, 6, 8]
>>> b = [v for k,v in enumerate(a) if not k%2]#четные значения ключей из массива
>>> b
[1, 3, 5, 7]
>>>
>>> list(enumerate(a)) #чтобы понимать как это работает
[(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 7), (7, 8)]
>>>
os.system("screen /usr/bin/java -server -jar ./Application.jar")
>>> x = {1: 2, 3: 4, 4: 3, 2: 1, 0: 0}
>>> sorted_by_value = sorted(x.items(), key=lambda kv: kv[1])
>>> sorted_by_value
[(0, 0), (2, 1), (1, 2), (4, 3), (3, 4)]
>>> dict(sorted_by_value)
{0: 0, 2: 1, 1: 2, 4: 3, 3: 4}
>>>