Português
Abrir no Telegram

TópicoВсем привет!

4 mensagens · –
M
Всем привет! Решал интерeсную задачу, но не решил Условие: For this exercise, we’ll try doing an experiment. If you flip a coin 100 times and write down an “H” for each heads and “T” for each tails, you’ll create a list that looks like “T T T T H H H H T T.” If you ask a human to make up 100 random coin flips, you’ll probably end up with alternating head-tail results like “H T H T H H T H T T,” which looks random (to humans), but isn’t mathematically random. A human will almost never write down a streak of six heads or six tails in a row, even though it is highly likely to happen in truly random coin flips. Humans are predictably bad at being random. Write a program to find out how often a streak of six heads or a streak of six tails comes up in a randomly generated list of heads and tails. Your program breaks up the experiment into two parts: the first part generates a list of randomly selected 'heads' and 'tails' values, and the second part checks if there is a streak in it. Put all of this code in a loop that repeats the experiment 10,000 times so we can find out what percentage of the coin flips contains a streak of six heads or tails in a row. As a hint, the function call random.randint(0, 1) will return a 0 value 50% of the time and a 1 value the other 50% of the time. Мое решение: import random numberOfStreaks = 0 ist = [] six_h = 'H' * 6 six_t = 'T' * 6 for experimentNumber in range(10000): # Code that creates a list of 100 'heads' or 'tails' values. x = random.randint(0, 1) if x == 0: ist.append('H') else: ist.append('T') # Code that checks if there is a streak of 6 heads or tails in a row. if six_h in ist or six_t in ist: numberOfStreaks += 1 print(numberOfStreaks) Подскажите, где может быть ошибка ? Я думаю что в if six_h in ist or six_t in ist, но не знаю в чем
  1. A
    а почему ошибка? выглядит вроде норм
ССообщество Python ПрограммистовСообщество Python Программистов@python_scripts · grupo · Tecnologia
4 169membros43escrevendo em 30 dias
Feed da comunidade Abrir no Telegram

Um feed público aberto do índice de busca ChatCrawler — “o Google do Telegram público”; atualizado à medida que a comunidade é rastreada. Horários em UTC.

Somente conteúdo público, API oficial do Telegram. Sobre · Perguntas frequentes · Limites do índice · Remover uma página · Catálogo · Busca · Como calculamos