print([[x, y, z] for x in range(3) for y in range(3) for z in range(3)])
# ну или на привычных циклах
res = []
for x in range(3):
for y in range(3):
for z in range(3):
res.append([x, y, z])
print(res)
import random
import itertools
def take_coins(max_coins):
while True:
raw_coins = input('возьмите монеты[{}..{}]'.format(1, max_coins))
try:
coins = int(raw_coins)
if not 1 <= coins <= max_coins:
raise ValueError()
except ValueError as ex:
print('неверные данные')
else:
return coins
def game(coins, players):
players = random.sample(players, len(players))
for player in itertools.cycle(players):
if coins == 0:
print('игрок {} проиграл'.format(player))
break
else:
print('{} ходит'.format(player))
coins -= take_coins(min(10, coins))
print('осталось {} монет'.format(coins))
if __name__ == '__main__':
game(coins=100, players=['Вася', 'Петя'])
просмотры * k1 + подписчики * k2 + ответы * k3
An offer listing ID is an alphanumeric token that uniquely identifies an item. Use the OfferListingId instead of an item's ASIN to add the item to the cart.
Type: String
Default: None
Valid Values: An Offer Listing ID
Constraint: Required if ASIN is not used.
# bad
b = 0
for item in lastnames:
lastname = lastnames[b]
b = b + 1
print(lastname)
# good
for lastname in lastnames:
print(lastname)
firstnames = ['Andrey', "Sasha", "Artem", "Roma"]
lastnames = [" veskii"," Kross"," Lylka"]
# можно так
for lastname in lastnames:
with open('{}.txt'.format(lastname), 'w') as f:
for i, firstname in enumerate(firstnames):
f.write('{} {} {}\n'.format(i, firstname, lastname))
# или так
names = dict((lastname, firstnames) for lastname in lastnames)
for lastname, names_list in names.items():
with open('{}.txt'.format(lastname), 'w') as f:
f.write(
'\n'.join(
'{} {} {}'.format(i, firstname, lastname) for i, firstname in enumerate(names_list)
)
)
def get_max(text):
count_map = {char:text.count(char) for char in set(text)}
return max(count_map, key=lambda char: count_map[char])