Предмет: Информатика, автор: almasbekowa

помогите пожалуйста
(python)
Проверить
корректность работы генератора псевдослучайных чисел языка
программирования с помощью оценки вероятности выпадения четных чисел на
выборке не меньше 1000 случайных чисел.

Вывести процент четных чисел.

Ответы

Автор ответа: wherethefux
0

import random  # Импортируем модуль random, который содержит функцию для генерации случайных чисел

# Устанавливаем количество случайных чисел, которые нужно сгенерировать

num_samples = 1000

# Инициализируем счетчик количества четных чисел

even_count = 0

# Генерируем случайные числа

for i in range(num_samples):

 # Генерируем случайное целое число от 0 до 100 (включительно)

 rand_int = random.randint(0, 100)

 # Проверяем, является ли случайное число четным

 if rand_int % 2 == 0:

   # Если четное, увеличиваем счетчик

   even_count += 1

# Вычисляем процент четных чисел

percent_even = even_count / num_samples * 100

# Выводим результат

print(f"Из {num_samples} выборок, {even_count} были четными ({percent_even:.2f}%).")

Похожие вопросы
Предмет: Английский язык, автор: Derauhdhdb
ПОМОГИТЕ ПОЖАЛУЙСТА

Ex. 1 Complete the sentences with compound nouns.
The first letter of each word is given.
0 My dad works on a big desktop computer in his office.
1 You need to type in a u _ _ _ _ _ _ _ to get onto this site.
2 I sometimes send my mum a t _ _ _ m _ _ _ _ _ _ to tell her where I am.
3 I need a l _ _ _ _ _ computer, so that I can carry it around.
4 This w _ _ _ _ _ _ is great for checking the meanings of new words.
5 If your I _ _ _ _ _ _ _ s _ _ _ _ _ is down, you won’t be able to go online.

Ex. 2 Complete the sentences with the opposite of the words in the box.
popular helpful fit healthy
comfortable cooperative sensitive loyal
0 That shop assistant is very unhelpful. She doesn’t know where anything is in the
store!
1 Neil needs to do more exercise as he’s quite _______________________
2 Tom sometimes says things which aren’t very kind – he’s a bit
_______________________
3 She’s never been ______________________to her friends – she’s always there for
them.
4 Try and work with me on this – don’t be so _______________________
5 It’s terribly _______________________ to eat all that fried food.
6 The school canteen is quite _______________________. Not many people eat there.
7 I hate sitting on this sofa. It’s really _______________________!
Ex. 3 Complete the sentences
1. Are you serious ___________ being a doctor?
2. Jessy is not very good ___________ Math and Science.
3. I’m responsible ___________ doing the washing up.
4. Many customers were disappointed __________ the new smartphone.
5. If you apply for this job, you will be involved __________ coordinating meetings and
interviews.
6. Dan is very keen __________ sports. He has played volleyball and basketball since
he was young.