Skip to content

Commit 3e5eb11

Browse files
commit code
1 parent a932eb4 commit 3e5eb11

File tree

4 files changed

+105
-9
lines changed

4 files changed

+105
-9
lines changed

Chapter2/SortAscending.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# 2.15 (Sort in Ascending Order) Write a script that inputs three different floating-point
2+
# numbers from the user. Display the numbers in increasing order. Recall that an if state-
3+
# ment’s suite can contain more than one statement. Prove that your script works by run-
4+
# ning it on all six possible orderings of the numbers. Does your script work with duplicate
5+
# numbers? [This is challenging. In later chapters you’ll do this more conveniently and with
6+
# many more numbers.]
7+
firstNumber = input("ENTER YOUR FIRST NUMBER")
8+
SecondNumber = input("ENTER YOUR SECOND NUMBER")
9+
ThirdNumber = input("ENTER YOUR THIRD NUMBER")
10+
11+
if firstNumber <= SecondNumber and SecondNumber >= ThirdNumber:
12+
print(firstNumber,)
13+
print(ThirdNumber)
14+
print(SecondNumber)
15+
elif firstNumber >= SecondNumber and SecondNumber <= ThirdNumber:
16+
print(ThirdNumber)
17+
print(SecondNumber)
18+
print(firstNumber)
19+
20+

CurrentDateTime.py

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,45 @@
1-
from datetime import datetime, timedelta
1+
# from datetime import datetime, timedelta
2+
#
3+
# d1 = datetime.now()
4+
# d2 = datetime(2021, 6, 1)p
5+
# diff = d1 - d2
6+
# print(diff)
7+
#
8+
# t = timedelta(weeks=0)
9+
# print(d1 + t)
10+
#
11+
# date_from_str = datetime.strptime("02/02/07 16:10:2", "%m/%d/%y %H:%M:%S")
12+
# print(date_from_str.hour)
13+
# print(d1.strftime("%A %d, %B %y"))
14+
# time = [1,2,3]
15+
# def gen():
16+
# count=0
17+
# while time:
18+
# yield count
19+
# count = count + 1
20+
# for i in gen():
21+
# print(i)
222

3-
d1 = datetime.now()
4-
d2 = datetime(2021, 6, 1)
5-
diff = d1 - d2
6-
print(diff)
23+
def counter(low, high, step=1):
24+
while low < high:
25+
yield low
26+
low += step
727

8-
t = timedelta(weeks=0)
9-
print(d1 + t)
1028

11-
date_from_str = datetime.strptime("02/02/07 16:10:2", "%m/%d/%y %H:%M:%S")
12-
print(date_from_str.hour)
29+
for i in counter(2, 10):
30+
print(i)
31+
32+
print(list(counter(2, 6, 2)))
33+
import collections
34+
35+
c1 = collections.Counter("OLAYINKA OLUWATOBI")
36+
print(c1)
37+
c2 = collections.Counter("hi you")
38+
print(c2)
39+
c1.subtract(c2)
40+
print(c1)
41+
42+
person = collections.namedtuple("person", "name age")
43+
44+
p1 = person(name="olayinka", age=17)
45+
print(p1.name)

TicTacToe.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from dataclasses import dataclass
2+
3+
4+
@dataclass(frozen =True)
5+
class player:
6+
name = str
7+
sign = str
8+
9+
# def __int__(self, name: str, sign: str) -> None:
10+
# self.name = name
11+
# self.sign = sign
12+
13+
14+
15+
if __name__ == '__main__':
16+
player1 = "tobi",

board.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Board:
2+
def __init__(self):
3+
self.board = [""] * 9
4+
5+
def display_board(self):
6+
for index, cell in enumerate(self.board):
7+
if index != 0 and index % 3 == 0:
8+
print()
9+
if index % 3 == 0:
10+
print("|", end="")
11+
print(f"{cell:^3}|", end="")
12+
13+
def is_cell_empty(self, position):
14+
return self.board[position - 1] == ""
15+
16+
def is_board_full(self):
17+
return all(self.board)
18+
19+
20+
21+
if __name__ == '__main__':
22+
board = Board()
23+
print(board.board)
24+
board.board[7] = '*'
25+
26+
27+
board.display_board()

0 commit comments

Comments
 (0)