-
Notifications
You must be signed in to change notification settings - Fork 0
/
source_2.py
129 lines (102 loc) · 3.14 KB
/
source_2.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import sqlite3
import hashlib
import random
def md5sum(value):
return hashlib.md5(value.encode()).hexdigest()
with sqlite3.connect("database.db") as db:
cursor = db.cursor()
query = """
CREATE TABLE IF NOT EXISTS users(
id INTEGER PRIMARY KEY,
name VARCHAR(30),
age INTEGER(3),
sex INTEGER NOT NULL DEFAULT 1,
balance INTEGER NOT NULL DEFAULT 2000,
login VARCHAR(15),
password VARCHAR(20)
);
CREATE TABLE IF NOT EXISTS casino(
name VARCHAR(50),
description TEXT(300),
balance BIGINT NOT NULL DEFAULT 10000
)
"""
cursor.executescript(query)
def registration():
name = input("Name: ")
age = int(input("Age: "))
sex = int(input("Sex: "))
login = input("Login: ")
password = input("Password: ")
try:
db = sqlite3.connect("database.db")
cursor = db.cursor()
db.create_function("md5", 1, md5sum)
cursor.execute("SELECT login FROM users WHERE login = ?", [login])
if cursor.fetchone() is None:
values = [name, age, sex, login, password]
cursor.execute("INSERT INTO users(name, age, sex, login, password) VALUES(?, ?, ?, ?, md5(?))", values)
db.commit()
else:
print("Такой логин уже существует!")
registration()
except sqlite3.Error as e:
print("Error", e)
finally:
cursor.close()
db.close()
def log_in():
login = input("Login: ")
password = input("Password: ")
try:
db = sqlite3.connect("database.db")
cursor = db.cursor()
db.create_function("md5", 1, md5sum)
cursor.execute("SELECT login FROM users WHERE login = ?", [login])
if cursor.fetchone() is None:
print("Такого логина не существует!")
else:
cursor.execute("SELECT password FROM users WHERE login = ? AND password = md5(?)", [login, password])
if cursor.fetchone() is None:
print("Пароль неверный!")
else:
play_casino(login)
except sqlite3.Error as e:
print("Error", e)
finally:
cursor.close()
db.close()
def play_casino(login):
print("\nCASINO 🥰😳")
try:
db = sqlite3.connect("database.db")
cursor = db.cursor()
cursor.execute("SELECT age FROM users WHERE login = ? AND age >= ?", [login, 18])
if cursor.fetchone() is None:
print("Вам недостаточно лет!")
else:
bet = int(input("Bet: "))
number = random.randint(1, 100)
balance = cursor.execute("SELECT balance FROM users WHERE login = ?", [login]).fetchone()[0]
if balance < bet:
print("Недостаточно средств, гуляй работать! 😉💖")
elif balance <= 0:
print("Недостаточно средств, гуляй работать! 😉💖")
else:
if number < 50:
cursor.execute("UPDATE users SET balance = balance - ? WHERE login = ?", [bet, login])
cursor.execute("UPDATE casino SET balance = balance + ?", [bet])
print("You lose! ❤")
else:
cursor.execute("UPDATE users SET balance = balance + ? WHERE login = ?", [bet, login])
cursor.execute("UPDATE casino SET balance = balance - ?", [bet])
print("You win! 😉😳")
db.commit()
play_casino(login)
except sqlite3.Error as e:
print("Error", e)
finally:
cursor.close()
db.close()
registration()
log_in()