-
Notifications
You must be signed in to change notification settings - Fork 0
/
ch09_games.py
33 lines (26 loc) · 985 Bytes
/
ch09_games.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Игры
# Демонстрирует создание модуля
class Player(object):
"""Участник игры"""
def __init__(self, name, score=0):
self.name = name
self.score = score
def __str__(self):
rep = self.name + ":\t" + str(self.score)
return rep
def ask_yes_no(question):
"""Задаёт вопрос с ответом 'да' или 'нет'"""
response = None
while response not in ("y", "n"):
response = input(question).lower()
return response
def ask_number(question, low, high):
"""Просит ввести число из заданного диапазона"""
response = None
while response not in range(low, high):
response = int(input(question))
return response
if __name__ == "__main__":
print("Вы запустили этот модуль напрямую, а не импортировали его")