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

Пайтон
Загадай число.

Помните, мы с вами отгадывали число?

Давайте теперь напишем программу, которая будет делать это за нас.

Сначала программа генерирует случайное число от 1 до 10.

Затем программа перебирает все варианты, пока не отгадает.

Пример результата:

1
2
3
Ответ: 4

Ответы

Автор ответа: dokaiimob
1

Ответ:

1)

import random

itemToGuess = int(input('Введите число от 0 до 10:'))

while(True):

oneTry = random.randint(0, 10)

if(oneTry == itemToGuess):

print(f'Вы загадали {oneTry}')

break

2)

import random

answer = random.randint(1, 10)

for i in range(1, 11):

if i == answer:

break

print(i)

print("Ответ: ", i)

Похожие вопросы
Предмет: Английский язык, автор: marinajaku
Вставьте пропущенные предлоги, где это необходимо.
1. The growth ... output... person rather than the growth ... total output is ... greater importance ... an economy.
2. The companies selling consumer goods recognize the importance ... consumer preferences; they spend over $40 billion ... a year... the US ... advertising trying to direct consumer preferences ... their own products.
3. An increase or a decrease ... total revenue may follow ... a price rise and a decrease ... the quantity produced accompanying it. The effect depends ... which change is larger - the change ... price or the change ... the quantity produced.
4. After a particular market is defined ... terms ... its product and its geographic area, the economist can study the workings... demand and supply ... that particular market.
5. As the price ... a good increases, consumers can buy less ... all goods, including ... the good whose price has risen.
6. Opportunity costs and amounts paid ... all resources are included ... total costs.
7. The output... beer... Russia's largest beer maker, Baltika Brewery, grew... 30 percent ... 1999 ... the previous year.
8. ... 1999, industrial production ... Russia increased... 7.9 percent but the output... agricultural sector decreased ... 0.6 percent compared ... 1998 level.
9. Every field, economics... particular, has its "schools" and groups. "Liberal" economists believe ... market system opportunities. But they also believe ... government support and regulation ... an economy. "Classical liberals" or the "Chicago Group" rely ... people's private choices as the rational basis ... the economic system. "Radical" economists, including ... Marxists and other critics, believe that free-market capitalism must result... depressions and mass unemployment. They assume that governments must run ... all economic units and make all economic decisions.
Предмет: Математика, автор: slava1811