├── .gitignore ├── .idea ├── .gitignore ├── Backend-django.iml ├── dbnavigator.xml ├── inspectionProfiles │ └── profiles_settings.xml ├── misc.xml ├── modules.xml └── vcs.xml ├── LICENSE ├── README.md ├── database ├── .idea │ └── database.iml ├── 1-dars │ ├── 1_dars_vazifa.db │ ├── 1_dars_vazifa.sqbpro │ ├── topshiriq-sql-1.txt.txt │ ├── users_db.db │ └── users_db.sqbpro ├── 3-dars │ └── .idea │ │ ├── .gitignore │ │ ├── 3-dars.iml │ │ ├── dbnavigator.xml │ │ ├── inspectionProfiles │ │ └── profiles_settings.xml │ │ ├── misc.xml │ │ ├── modules.xml │ │ └── vcs.xml └── 4-dars │ ├── .idea │ ├── .gitignore │ ├── 4-dars.iml │ ├── dataSources.xml │ ├── dbnavigator.xml │ ├── inspectionProfiles │ │ └── profiles_settings.xml │ ├── misc.xml │ ├── modules.xml │ ├── sqldialects.xml │ └── vcs.xml │ ├── for_db.py │ ├── identifier.sqlite │ └── main.py └── python ├── 11-dars-one-linear-python.ipynb ├── 12-dars-mehmonxona.py ├── 13-dars-OPP-1-qism.ipynb ├── 14-Polimorfizm-Paket-modul ├── paket1 │ ├── __init__.py │ ├── modul1.py │ └── modul2.py ├── paket2 │ ├── __init__.py │ ├── modul1.py │ └── modul2.py └── paket3 │ ├── __init__.py │ ├── add.py │ ├── div.py │ ├── mul.py │ ├── result.py │ └── sub.py ├── 14-dars-Math-Datetime.ipynb ├── 14-dars-OOP-2-qism.ipynb ├── 15-api-result.json ├── 15-dars-json.ipynb ├── 15-json1.json ├── 15-json2.json ├── 15-students.json ├── 16-dars-loyiha-test-dasturi.py ├── 16-tests.json ├── 16-users.json ├── 5-dars_if-elif-else.ipynb ├── 6-dars-for-loop-1.ipynb ├── 6-dars-for-loop-2.ipynb ├── 6-dars-for-loop-3.ipynb ├── 7-dars-while-x-va-0-oyini.ipynb ├── 7-dars-x_o_game.py ├── 8-dars-funksiya.ipynb └── 9-dars-takrorlash.ipynb /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Editor-based HTTP Client requests 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | -------------------------------------------------------------------------------- /.idea/Backend-django.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/dbnavigator.xml: -------------------------------------------------------------------------------- 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 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Umidbek 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Backend-django -------------------------------------------------------------------------------- /database/.idea/database.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /database/1-dars/1_dars_vazifa.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-Umidjon/Backend-django/685bb79d2022109a19e09aff3f6afbf841a805d1/database/1-dars/1_dars_vazifa.db -------------------------------------------------------------------------------- /database/1-dars/1_dars_vazifa.sqbpro: -------------------------------------------------------------------------------- 1 |
-- INSERT INTO city (city, country, postcode) 2 | -- VALUES('Tashkent', 'Uzbekistan', '99890'); 3 | 4 | -- INSERT INTO city (city, country, postcode) 5 | -- VALUES('London', 'UK', '23545'); 6 | 7 | -- INSERT INTO city(city, country, postcode) 8 | -- VALUES('Budapesht', 'Vengriya', 12345); 9 | 10 | -- INSERT INTO city (city, country, postcode) 11 | -- VALUES ('Sidney', 'Australiya', 67342); 12 | 13 | -- INSERT INTO city (city, country, postcode) 14 | -- VALUES ('Tokiyo', 'Yaponiya', 67489); 15 | 16 | -- INSERT INTO city (city, country, postcode) 17 | -- VALUES ('Berlin', 'Germaniya', 43871); 18 | 19 | -- INSERT INTO city(city, country, postcode) 20 | -- VALUES ('Rim', 'Italiya', 23875); 21 | 22 | -- INSERT INTO city(city, country, postcode) 23 | -- VALUES ('Astana', 'Kazakistan', 32878); 24 | 25 | -- INSERT INTO city(city, country, postcode) 26 | -- VALUES ('Moskva', 'Rassiya', 43892); 27 | 28 | -- SELECT * FROM city WHERE country = 'Uzbekistan'; 29 | 30 | 31 | -- INSERT INTO books(name, author, category, price) 32 | -- VALUES 33 | -- ('Dasturlash asoslari', 'Anvar Narzullayev', 'Ilmiy', 50000), 34 | -- ('Handbook', 'I do not know', 'Ilmiy', 76000), 35 | -- ('Harry Poter', 'John Smith', 'Badiiy', 645680), 36 | -- ('Sariq devni minib', 'Otkir Hoshimov', 'Badiiy', 123000), 37 | -- ('Xamsa', 'Alisher Navoiy', 'Badiiy', 4576300), 38 | -- ('Islom tarixi', 'Shayx Muhammad Sodiq', 'Diniy', 90500), 39 | -- ('Guliverning sayohatlari', 'Aka-uka grimlar', 'Badiiy', 329800), 40 | -- ('Bonk', 'Nalaliya Bonk', 'Ilmiy', 25000), 41 | -- ('Qashqirlar makoni', 'Otaturk', 'Toqima', 34870), 42 | -- ('Mehrobdan Chayon', 'Otkir Hoshimov', 'Badiiy', 23000); 43 | 44 | -- SELECT * FROM books WHERE author='Anvar Narzullayev'; 45 | 46 | -- INSERT INTO user (first_name, last_name, age) 47 | -- VALUES 48 | -- ('Umidbek', 'Maxammadsoliyev', 19), 49 | -- ('Odlijon', 'Maxammadsoliyev', 17), 50 | -- ('Muhammadziyo', 'Avazbekov', 5), 51 | -- ('Abdulhadiy', 'Rahmonov', 24), 52 | -- ('Asqar', 'Kattabekov', 34), 53 | -- ('Nodir', 'Abdusattorov', 45), 54 | -- ('Odil', 'Ahmedov', 35); 55 | 56 | -- SELECT * FROM user WHERE age = 25; 57 | -- SELECT first_name, last_name FROM user WHERE age = 25; 58 | SELECT first_name, last_name FROM user WHERE id = 3;
59 | -------------------------------------------------------------------------------- /database/1-dars/topshiriq-sql-1.txt.txt: -------------------------------------------------------------------------------- 1 | 1. city jadavalini yarating. unda (id, city, country, postcode) bo'lsin. 2 | 2. books jadavalini yarating. unda (id, name, author, category, price) bo'lsin. 3 | 4 | 1.1 city jadavaliga 10 element qoshing. 5 | 1.2 city jadavalidan country = "country1" ga tegishli elementlarni to'plang. 6 | 7 | 8 | 2.1 books jadavaliga 10 element qoshing. 9 | 2.2 books jadavalidan author = "author1" ga tegishli elementlarni to'plang. 10 | 11 | 12 | 3.user jadavalini yarating. unda (id, first_name, last_name, age) bo'lsin. 13 | 3.1. user jadvalidan 25 yoshga teng bo'lgan userlarni hamma malumotini oling? 14 | 3.2. user jadvalidan 25 yoshga teng bo'lgan userlarni first_name va age malumotlarini oling? 15 | 3.3. user jadvalidan id = 3 bo'lgan userni first_name va last_name malumotlarini oling? -------------------------------------------------------------------------------- /database/1-dars/users_db.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-Umidjon/Backend-django/685bb79d2022109a19e09aff3f6afbf841a805d1/database/1-dars/users_db.db -------------------------------------------------------------------------------- /database/1-dars/users_db.sqbpro: -------------------------------------------------------------------------------- 1 |
-- INSERT INTO users (first_name,last_name,age) 2 | -- VALUES( 'Odiljon', 'Maxammadsoliyev',17); 3 | 4 | -- SELECT age, first_name, last_name FROM users; -- Bittalab ma'lumotlarni olish 5 | -- SELECT * FROM users; -- Hamma ma'lumotlarni olish 6 | 7 | -- SELECT * FROM users WHERE age>18; -- Shart orqali olish 8 | -- SELECT * FROM users WHERE first_name = 'Umidbek' AND age > 18; 9 | SELECT last_name as familiya, first_name as ism, age as yosh FROM users;
10 | -------------------------------------------------------------------------------- /database/3-dars/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Editor-based HTTP Client requests 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | -------------------------------------------------------------------------------- /database/3-dars/.idea/3-dars.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /database/3-dars/.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /database/3-dars/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /database/3-dars/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /database/3-dars/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /database/4-dars/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Editor-based HTTP Client requests 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | -------------------------------------------------------------------------------- /database/4-dars/.idea/4-dars.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /database/4-dars/.idea/dataSources.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | sqlite.xerial 6 | true 7 | org.sqlite.JDBC 8 | jdbc:sqlite:identifier.sqlite 9 | $ProjectFileDir$ 10 | 11 | 12 | -------------------------------------------------------------------------------- /database/4-dars/.idea/dbnavigator.xml: -------------------------------------------------------------------------------- 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 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 |
158 |
159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 |
554 | 555 | 556 | 557 | -------------------------------------------------------------------------------- /database/4-dars/.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /database/4-dars/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /database/4-dars/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /database/4-dars/.idea/sqldialects.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /database/4-dars/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /database/4-dars/for_db.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-Umidjon/Backend-django/685bb79d2022109a19e09aff3f6afbf841a805d1/database/4-dars/for_db.py -------------------------------------------------------------------------------- /database/4-dars/identifier.sqlite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-Umidjon/Backend-django/685bb79d2022109a19e09aff3f6afbf841a805d1/database/4-dars/identifier.sqlite -------------------------------------------------------------------------------- /database/4-dars/main.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-Umidjon/Backend-django/685bb79d2022109a19e09aff3f6afbf841a805d1/database/4-dars/main.py -------------------------------------------------------------------------------- /python/11-dars-one-linear-python.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "source": [ 6 | "### LIST COMPEHENSION\n", 7 | "### 1-misol" 8 | ], 9 | "metadata": { 10 | "collapsed": false, 11 | "pycharm": { 12 | "name": "#%% md\n" 13 | } 14 | } 15 | }, 16 | { 17 | "cell_type": "code", 18 | "execution_count": 1, 19 | "outputs": [ 20 | { 21 | "name": "stdout", 22 | "output_type": "stream", 23 | "text": [ 24 | "['Toshkent', \"Farg'ona\", 'Jizzax', 'Andijon', 'Samarqand', 'Buxoro']\n" 25 | ] 26 | } 27 | ], 28 | "source": [ 29 | "regions = [[\"Toshkent\", \"Buxoro\"], [\"Farg'ona\", \"Jizzax\"],\n", 30 | " [\"Jizzax\", \"Navoiy\"], [\"Andijon\", \"Farg'ona\"],\n", 31 | " [\"Samarqand\", \"Andijon\"], [\"Buxoro\", \"Samarqand\"]]\n", 32 | "\n", 33 | "a = [r[0] for r in regions]\n", 34 | "\n", 35 | "print(a)" 36 | ], 37 | "metadata": { 38 | "collapsed": false, 39 | "pycharm": { 40 | "name": "#%%\n" 41 | } 42 | } 43 | }, 44 | { 45 | "cell_type": "markdown", 46 | "source": [ 47 | "### 2-misol\n", 48 | "### sonlar = [1, 2, 3, 4, 5]\n", 49 | "### Ushbu listdagi toq sonlarni 2 ga ko'paytirib yangi listga o'tkazing." 50 | ], 51 | "metadata": { 52 | "collapsed": false, 53 | "pycharm": { 54 | "name": "#%% md\n" 55 | } 56 | } 57 | }, 58 | { 59 | "cell_type": "code", 60 | "execution_count": 2, 61 | "outputs": [ 62 | { 63 | "name": "stdout", 64 | "output_type": "stream", 65 | "text": [ 66 | "[2, 4, 6, 8, 10]\n" 67 | ] 68 | } 69 | ], 70 | "source": [ 71 | "sonlar = [1, 2, 3, 4, 5]\n", 72 | "new_list = [i * 2 for i in sonlar]\n", 73 | "\n", 74 | "print(new_list)" 75 | ], 76 | "metadata": { 77 | "collapsed": false, 78 | "pycharm": { 79 | "name": "#%%\n" 80 | } 81 | } 82 | }, 83 | { 84 | "cell_type": "markdown", 85 | "source": [ 86 | "### 3-misol\n", 87 | "### lst = [1, 2, 3, 'Alice', 'Alice']\n", 88 | "### listdagi ma'lum elementning ilk uchragan indexini topish" 89 | ], 90 | "metadata": { 91 | "collapsed": false, 92 | "pycharm": { 93 | "name": "#%% md\n" 94 | } 95 | } 96 | }, 97 | { 98 | "cell_type": "code", 99 | "execution_count": 4, 100 | "outputs": [ 101 | { 102 | "name": "stdout", 103 | "output_type": "stream", 104 | "text": [ 105 | "3\n" 106 | ] 107 | } 108 | ], 109 | "source": [ 110 | "lst = [1, 2, 3, 'Alice', 'Alice']\n", 111 | "print(lst.index(\"Alice\"))" 112 | ], 113 | "metadata": { 114 | "collapsed": false, 115 | "pycharm": { 116 | "name": "#%%\n" 117 | } 118 | } 119 | }, 120 | { 121 | "cell_type": "markdown", 122 | "source": [ 123 | "### listdagi ma'lum elementning barcha indexlarini topish" 124 | ], 125 | "metadata": { 126 | "collapsed": false, 127 | "pycharm": { 128 | "name": "#%% md\n" 129 | } 130 | } 131 | }, 132 | { 133 | "cell_type": "code", 134 | "execution_count": 6, 135 | "outputs": [ 136 | { 137 | "name": "stdout", 138 | "output_type": "stream", 139 | "text": [ 140 | "[3, 4]\n" 141 | ] 142 | } 143 | ], 144 | "source": [ 145 | "lst = [1, 2, 3, 'Alice', 'Alice']\n", 146 | "indxs = [i for i in range(len(lst)) if lst[i] == 'Alice']\n", 147 | "\n", 148 | "print(indxs)" 149 | ], 150 | "metadata": { 151 | "collapsed": false, 152 | "pycharm": { 153 | "name": "#%%\n" 154 | } 155 | } 156 | }, 157 | { 158 | "cell_type": "markdown", 159 | "source": [ 160 | "### 4-misol\n", 161 | "### (ism, $-pul) Miilionerni toping." 162 | ], 163 | "metadata": { 164 | "collapsed": false, 165 | "pycharm": { 166 | "name": "#%% md\n" 167 | } 168 | } 169 | }, 170 | { 171 | "cell_type": "code", 172 | "execution_count": 9, 173 | "outputs": [ 174 | { 175 | "name": "stdout", 176 | "output_type": "stream", 177 | "text": [ 178 | "['Ann', 'Zach']\n" 179 | ] 180 | } 181 | ], 182 | "source": [ 183 | "people = [(\"John\", 240_000), (\"Alice\", 120_000), (\"Ann\", 1_100_000), (\"Zach\", 1_144_000)]\n", 184 | "\n", 185 | "millioners = [k for k, v in people if v > 1_000_000]\n", 186 | "print(millioners)" 187 | ], 188 | "metadata": { 189 | "collapsed": false, 190 | "pycharm": { 191 | "name": "#%%\n" 192 | } 193 | } 194 | }, 195 | { 196 | "cell_type": "code", 197 | "execution_count": 25, 198 | "outputs": [], 199 | "source": [ 200 | "def find_millioners(people):\n", 201 | " millioners = [k for k, v in people.items() if v >= 1_000_000]\n", 202 | " return millioners\n", 203 | "\n" 204 | ], 205 | "metadata": { 206 | "collapsed": false, 207 | "pycharm": { 208 | "name": "#%%\n" 209 | } 210 | } 211 | }, 212 | { 213 | "cell_type": "code", 214 | "execution_count": 27, 215 | "outputs": [], 216 | "source": [ 217 | "people_data1 = {'Alice': 1_000_000, 'Bob': 998_170, 'Carol': 1_229_080, 'Frank': 881_230, 'Eve': 93_121}\n", 218 | "people_data2 = {'Alice': 1_000_000, 'Bob': 998_170, 'Frank': 1_881_230, 'Eve': 93_121}\n", 219 | "\n", 220 | "\n", 221 | "def test():\n", 222 | " assert find_millioners(people_data1) == ['Alice', \"Carol\"]\n", 223 | " assert find_millioners(people_data2) == ['Alice', \"Frank\"]\n", 224 | "\n", 225 | "\n", 226 | "test()\n", 227 | "# find_millioners(people_data2)" 228 | ], 229 | "metadata": { 230 | "collapsed": false, 231 | "pycharm": { 232 | "name": "#%%\n" 233 | } 234 | } 235 | }, 236 | { 237 | "cell_type": "markdown", 238 | "source": [ 239 | "### 5-misol\n", 240 | "### [(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)]" 241 | ], 242 | "metadata": { 243 | "collapsed": false, 244 | "pycharm": { 245 | "name": "#%% md\n" 246 | } 247 | } 248 | }, 249 | { 250 | "cell_type": "code", 251 | "execution_count": 30, 252 | "outputs": [ 253 | { 254 | "name": "stdout", 255 | "output_type": "stream", 256 | "text": [ 257 | "[(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)]\n" 258 | ] 259 | } 260 | ], 261 | "source": [ 262 | "print([(i, k) for i in range(3) for k in range(3)])" 263 | ], 264 | "metadata": { 265 | "collapsed": false, 266 | "pycharm": { 267 | "name": "#%%\n" 268 | } 269 | } 270 | }, 271 | { 272 | "cell_type": "markdown", 273 | "source": [ 274 | "### 6-misol\n", 275 | "### Matndani uzulnigi 7 ta harfdan ortiq bo'lgan so'zlarni toping" 276 | ], 277 | "metadata": { 278 | "collapsed": false, 279 | "pycharm": { 280 | "name": "#%% md\n" 281 | } 282 | } 283 | }, 284 | { 285 | "cell_type": "code", 286 | "execution_count": 37, 287 | "outputs": [ 288 | { 289 | "name": "stdout", 290 | "output_type": "stream", 291 | "text": [ 292 | "[['Ishmael.', 'precisely'], ['particular', 'interest'], [], ['regulating', 'circulation.']]\n" 293 | ] 294 | } 295 | ], 296 | "source": [ 297 | "text = '''Call me Ishmael. Some years ago - never mind how long precisely - having little\n", 298 | "or no money in my purse, and nothing particular to interest me on shore, I thought I would\n", 299 | "sail about a little and see the watery part of the world. It is a way I have of driving off\n", 300 | "the spleen, and regulating the circulation. - Moby Dick '''\n", 301 | "\n", 302 | "# print(text.split(\"\\n\"))\n", 303 | "\n", 304 | "w = [[i for i in r.split() if len(i) > 7] for r in text.split(\"\\n\")]\n", 305 | "\n", 306 | "print(w)" 307 | ], 308 | "metadata": { 309 | "collapsed": false, 310 | "pycharm": { 311 | "name": "#%%\n" 312 | } 313 | } 314 | }, 315 | { 316 | "cell_type": "markdown", 317 | "source": [ 318 | "## Ziplash" 319 | ], 320 | "metadata": { 321 | "collapsed": false, 322 | "pycharm": { 323 | "name": "#%% md\n" 324 | } 325 | } 326 | }, 327 | { 328 | "cell_type": "code", 329 | "execution_count": 39, 330 | "outputs": [ 331 | { 332 | "name": "stdout", 333 | "output_type": "stream", 334 | "text": [ 335 | "[('ism', 'Akmal'), ('familiya', 'Tohirov'), ('yosh', 16)]\n" 336 | ] 337 | } 338 | ], 339 | "source": [ 340 | "lst_1 = ['ism', 'familiya', 'yosh']\n", 341 | "lst_2 = ['Akmal', 'Tohirov', 16]\n", 342 | "\n", 343 | "zipped = list(zip(lst_1, lst_2))\n", 344 | "print(zipped)" 345 | ], 346 | "metadata": { 347 | "collapsed": false, 348 | "pycharm": { 349 | "name": "#%%\n" 350 | } 351 | } 352 | }, 353 | { 354 | "cell_type": "markdown", 355 | "source": [ 356 | "## Unziplash" 357 | ], 358 | "metadata": { 359 | "collapsed": false, 360 | "pycharm": { 361 | "name": "#%% md\n" 362 | } 363 | } 364 | }, 365 | { 366 | "cell_type": "code", 367 | "execution_count": 40, 368 | "outputs": [ 369 | { 370 | "name": "stdout", 371 | "output_type": "stream", 372 | "text": [ 373 | "('ism', 'familiya', 'yosh')\n", 374 | "('Akmal', 'Tohirov', 16)\n" 375 | ] 376 | } 377 | ], 378 | "source": [ 379 | "lst1, lst2 = zip(*zipped)\n", 380 | "print(lst1)\n", 381 | "print(lst2)" 382 | ], 383 | "metadata": { 384 | "collapsed": false, 385 | "pycharm": { 386 | "name": "#%%\n" 387 | } 388 | } 389 | }, 390 | { 391 | "cell_type": "markdown", 392 | "source": [ 393 | "### 7-misol" 394 | ], 395 | "metadata": { 396 | "collapsed": false, 397 | "pycharm": { 398 | "name": "#%% md\n" 399 | } 400 | } 401 | }, 402 | { 403 | "cell_type": "code", 404 | "execution_count": 44, 405 | "outputs": [ 406 | { 407 | "name": "stdout", 408 | "output_type": "stream", 409 | "text": [ 410 | "[{'name': 'Alice', 'salary': 180000, 'job': 'data scientist'}, {'name': 'Bob', 'salary': 99000, 'job': 'project manager'}, {'name': 'Frank', 'salary': 87000, 'job': 'backend developer'}]\n" 411 | ] 412 | } 413 | ], 414 | "source": [ 415 | "ustun_nomlari = ['name', 'salary', 'job']\n", 416 | "qatorlar = [('Alice', 180_000, 'data scientist'),\n", 417 | " ('Bob', 99_000, 'project manager'),\n", 418 | " ('Frank', 87_000, 'backend developer')]\n", 419 | "\n", 420 | "db = [dict(zip(ustun_nomlari, row)) for row in qatorlar]\n", 421 | "\n", 422 | "print(db)" 423 | ], 424 | "metadata": { 425 | "collapsed": false, 426 | "pycharm": { 427 | "name": "#%%\n" 428 | } 429 | } 430 | }, 431 | { 432 | "cell_type": "markdown", 433 | "source": [ 434 | "### lambda()" 435 | ], 436 | "metadata": { 437 | "collapsed": false, 438 | "pycharm": { 439 | "name": "#%% md\n" 440 | } 441 | } 442 | }, 443 | { 444 | "cell_type": "code", 445 | "execution_count": 45, 446 | "outputs": [ 447 | { 448 | "name": "stdout", 449 | "output_type": "stream", 450 | "text": [ 451 | "6\n" 452 | ] 453 | } 454 | ], 455 | "source": [ 456 | "summa = lambda a, b, c: a + b + c\n", 457 | "print(summa(1, 2, 3))" 458 | ], 459 | "metadata": { 460 | "collapsed": false, 461 | "pycharm": { 462 | "name": "#%%\n" 463 | } 464 | } 465 | }, 466 | { 467 | "cell_type": "code", 468 | "execution_count": 46, 469 | "outputs": [ 470 | { 471 | "name": "stdout", 472 | "output_type": "stream", 473 | "text": [ 474 | "6\n" 475 | ] 476 | } 477 | ], 478 | "source": [ 479 | "print((lambda a, b, c: a + b + c)(1, 2, 3))" 480 | ], 481 | "metadata": { 482 | "collapsed": false, 483 | "pycharm": { 484 | "name": "#%%\n" 485 | } 486 | } 487 | }, 488 | { 489 | "cell_type": "code", 490 | "execution_count": 47, 491 | "outputs": [ 492 | { 493 | "name": "stdout", 494 | "output_type": "stream", 495 | "text": [ 496 | "27\n" 497 | ] 498 | } 499 | ], 500 | "source": [ 501 | "print((lambda x: x * 3)(9))" 502 | ], 503 | "metadata": { 504 | "collapsed": false, 505 | "pycharm": { 506 | "name": "#%%\n" 507 | } 508 | } 509 | }, 510 | { 511 | "cell_type": "markdown", 512 | "source": [ 513 | "## map()" 514 | ], 515 | "metadata": { 516 | "collapsed": false, 517 | "pycharm": { 518 | "name": "#%% md\n" 519 | } 520 | } 521 | }, 522 | { 523 | "cell_type": "markdown", 524 | "source": [ 525 | "### 9-misol: sonlarni integerga o'tkazing" 526 | ], 527 | "metadata": { 528 | "collapsed": false, 529 | "pycharm": { 530 | "name": "#%% md\n" 531 | } 532 | } 533 | }, 534 | { 535 | "cell_type": "code", 536 | "execution_count": 50, 537 | "outputs": [ 538 | { 539 | "name": "stdout", 540 | "output_type": "stream", 541 | "text": [ 542 | "[4, 8, 6, 5, 3, 2, 8, 9, 2, 5]\n", 543 | "\n" 544 | ] 545 | } 546 | ], 547 | "source": [ 548 | "str_nums = [\"4\", \"8\", \"6\", \"5\", \"3\", \"2\", \"8\", \"9\", \"2\", \"5\"]\n", 549 | "int_nums = list(map(int, str_nums))\n", 550 | "print(int_nums)\n", 551 | "print(type(int_nums))" 552 | ], 553 | "metadata": { 554 | "collapsed": false, 555 | "pycharm": { 556 | "name": "#%%\n" 557 | } 558 | } 559 | }, 560 | { 561 | "cell_type": "markdown", 562 | "source": [ 563 | "### 10-misol: sonlarni kvadratga ko'taring\n", 564 | "### numbers = [1, 2, 3, 4, 5]" 565 | ], 566 | "metadata": { 567 | "collapsed": false, 568 | "pycharm": { 569 | "name": "#%% md\n" 570 | } 571 | } 572 | }, 573 | { 574 | "cell_type": "code", 575 | "execution_count": 51, 576 | "outputs": [ 577 | { 578 | "name": "stdout", 579 | "output_type": "stream", 580 | "text": [ 581 | "[1, 4, 9, 16, 25]\n" 582 | ] 583 | } 584 | ], 585 | "source": [ 586 | "numbers = [1, 2, 3, 4, 5]\n", 587 | "print(list(map(lambda x: x ** 2, numbers)))" 588 | ], 589 | "metadata": { 590 | "collapsed": false, 591 | "pycharm": { 592 | "name": "#%%\n" 593 | } 594 | } 595 | }, 596 | { 597 | "cell_type": "markdown", 598 | "source": [ 599 | "### 11-misol: listdagi elementlarni mos indexi bo'yicha ayiring." 600 | ], 601 | "metadata": { 602 | "collapsed": false, 603 | "pycharm": { 604 | "name": "#%% md\n" 605 | } 606 | } 607 | }, 608 | { 609 | "cell_type": "code", 610 | "execution_count": 52, 611 | "outputs": [ 612 | { 613 | "name": "stdout", 614 | "output_type": "stream", 615 | "text": [ 616 | "[1, 1, 1]\n" 617 | ] 618 | } 619 | ], 620 | "source": [ 621 | "print(list(map(lambda x, y: x - y, [2, 4, 6], [1, 3, 5])))" 622 | ], 623 | "metadata": { 624 | "collapsed": false, 625 | "pycharm": { 626 | "name": "#%%\n" 627 | } 628 | } 629 | }, 630 | { 631 | "cell_type": "markdown", 632 | "source": [ 633 | "### 12-misol: Listdagi elementlarni katta harfga o'tkazing\n", 634 | "### string_it = [\"processing\", \"strings\", \"with\", \"map\"]" 635 | ], 636 | "metadata": { 637 | "collapsed": false, 638 | "pycharm": { 639 | "name": "#%% md\n" 640 | } 641 | } 642 | }, 643 | { 644 | "cell_type": "code", 645 | "execution_count": 54, 646 | "outputs": [ 647 | { 648 | "name": "stdout", 649 | "output_type": "stream", 650 | "text": [ 651 | "['PROCESSING', 'STRINGS', 'WITH', 'MAP']\n", 652 | "['Processing', 'Strings', 'With', 'Map']\n" 653 | ] 654 | } 655 | ], 656 | "source": [ 657 | "string_it = [\"processing\", \"strings\", \"with\", \"map\"]\n", 658 | "\n", 659 | "print(list(map(str.upper, string_it)))\n", 660 | "print(list(map(str.title, string_it)))" 661 | ], 662 | "metadata": { 663 | "collapsed": false, 664 | "pycharm": { 665 | "name": "#%%\n" 666 | } 667 | } 668 | }, 669 | { 670 | "cell_type": "markdown", 671 | "source": [ 672 | "### Reduce()\n", 673 | "### 13-misol: faktorialni toping: !4 = 1*2*3*4" 674 | ], 675 | "metadata": { 676 | "collapsed": false, 677 | "pycharm": { 678 | "name": "#%% md\n" 679 | } 680 | } 681 | }, 682 | { 683 | "cell_type": "code", 684 | "execution_count": 55, 685 | "outputs": [ 686 | { 687 | "name": "stdout", 688 | "output_type": "stream", 689 | "text": [ 690 | "24\n" 691 | ] 692 | } 693 | ], 694 | "source": [ 695 | "from functools import reduce\n", 696 | "\n", 697 | "print(reduce(lambda x, y: x * y, range(1, 5)))" 698 | ], 699 | "metadata": { 700 | "collapsed": false, 701 | "pycharm": { 702 | "name": "#%%\n" 703 | } 704 | } 705 | }, 706 | { 707 | "cell_type": "markdown", 708 | "source": [ 709 | "### Oson-1. longWord(word1, word2) - bu funksiya berilgan ikkita string eng uzunini print qilib bersin." 710 | ], 711 | "metadata": { 712 | "collapsed": false, 713 | "pycharm": { 714 | "name": "#%% md\n" 715 | } 716 | } 717 | }, 718 | { 719 | "cell_type": "code", 720 | "source": [ 721 | "def longWord(word1, word2):\n", 722 | " print(word1 if len(word1) > len(word2) else word2)\n", 723 | "\n", 724 | "\n", 725 | "longWord('salomlar', 'katta')" 726 | ], 727 | "metadata": { 728 | "collapsed": false, 729 | "pycharm": { 730 | "name": "#%%\n" 731 | } 732 | }, 733 | "execution_count": 58, 734 | "outputs": [ 735 | { 736 | "name": "stdout", 737 | "output_type": "stream", 738 | "text": [ 739 | "salomlar\n" 740 | ] 741 | } 742 | ] 743 | }, 744 | { 745 | "cell_type": "markdown", 746 | "source": [ 747 | "### Oson-2. wordCount(matn) - bu funksiya berilgan matndan nechta so'z borligini aniqlab sonni return qiladi.\n", 748 | "### Masalan: \"Python Django Hello Apple Network\" da 5 ta so'z bor." 749 | ], 750 | "metadata": { 751 | "collapsed": false, 752 | "pycharm": { 753 | "name": "#%% md\n" 754 | } 755 | } 756 | }, 757 | { 758 | "cell_type": "code", 759 | "source": [ 760 | "from functools import reduce\n", 761 | "\n", 762 | "\n", 763 | "def wordCount(matn):\n", 764 | " return len(matn.split())\n", 765 | "\n", 766 | "\n", 767 | "print(wordCount(\"Python Django Hello Apple Network\"))" 768 | ], 769 | "metadata": { 770 | "collapsed": false, 771 | "pycharm": { 772 | "name": "#%%\n" 773 | } 774 | }, 775 | "execution_count": 60, 776 | "outputs": [ 777 | { 778 | "name": "stdout", 779 | "output_type": "stream", 780 | "text": [ 781 | "5\n" 782 | ] 783 | } 784 | ] 785 | }, 786 | { 787 | "cell_type": "markdown", 788 | "source": [ 789 | "### Oson-3. findElements(myList) - bu funksiya berilgan myList dan yoq bolgan sonlarni listini return qilsin.\n", 790 | "### Masalan: [6, 5, 9, 3, 1] -> [2, 4, 7, 8]" 791 | ], 792 | "metadata": { 793 | "collapsed": false, 794 | "pycharm": { 795 | "name": "#%% md\n" 796 | } 797 | } 798 | }, 799 | { 800 | "cell_type": "code", 801 | "source": [ 802 | "def findElements(myList):\n", 803 | " return [x for x in range(1, max(myList) + 1) if x not in myList]\n", 804 | "\n", 805 | "\n", 806 | "print(findElements([1, 4, 7, 9]))" 807 | ], 808 | "metadata": { 809 | "collapsed": false, 810 | "pycharm": { 811 | "name": "#%%\n" 812 | } 813 | }, 814 | "execution_count": 85, 815 | "outputs": [ 816 | { 817 | "name": "stdout", 818 | "output_type": "stream", 819 | "text": [ 820 | "[2, 3, 5, 6, 8]\n" 821 | ] 822 | } 823 | ] 824 | }, 825 | { 826 | "cell_type": "markdown", 827 | "source": [ 828 | "### Oson-4. removeElement(myList, elem)-berilgan myList dan elem ni o'chirib tashlang." 829 | ], 830 | "metadata": { 831 | "collapsed": false, 832 | "pycharm": { 833 | "name": "#%% md\n" 834 | } 835 | } 836 | }, 837 | { 838 | "cell_type": "code", 839 | "source": [ 840 | "def removeElement(myList, elem):\n", 841 | " myList.remove(elem)\n", 842 | "\n", 843 | "\n", 844 | "res = [1, 4, 7, 9]\n", 845 | "removeElement(res, 1)\n", 846 | "print(res)" 847 | ], 848 | "metadata": { 849 | "collapsed": false, 850 | "pycharm": { 851 | "name": "#%%\n" 852 | } 853 | }, 854 | "execution_count": 69, 855 | "outputs": [ 856 | { 857 | "name": "stdout", 858 | "output_type": "stream", 859 | "text": [ 860 | "[4, 7, 9]\n" 861 | ] 862 | } 863 | ] 864 | }, 865 | { 866 | "cell_type": "markdown", 867 | "source": [ 868 | "### Oson-5. findWeekDay(orderNumber) - bu funksiya berilgan orderNumber, yani hafta kuni\n", 869 | "### tartibini beradi. Shu tartib boyicha hafta kunini string korinishda return qiling.\n", 870 | "### Masalan: orderNumber = 4 Natija: Payshanba" 871 | ], 872 | "metadata": { 873 | "collapsed": false, 874 | "pycharm": { 875 | "name": "#%% md\n" 876 | } 877 | } 878 | }, 879 | { 880 | "cell_type": "code", 881 | "source": [ 882 | "def findWeekDay(orderNumber):\n", 883 | " weekdays = dict(\n", 884 | " zip(range(1, 8), ['dushanaba', 'seshanaba', 'chorshanaba', 'payshanaba', 'juma', 'shanaba', 'yakshanaba']))\n", 885 | "\n", 886 | " return weekdays[orderNumber]\n", 887 | "\n", 888 | "\n", 889 | "print(findWeekDay(4))" 890 | ], 891 | "metadata": { 892 | "collapsed": false, 893 | "pycharm": { 894 | "name": "#%%\n" 895 | } 896 | }, 897 | "execution_count": 86, 898 | "outputs": [ 899 | { 900 | "name": "stdout", 901 | "output_type": "stream", 902 | "text": [ 903 | "payshanaba\n" 904 | ] 905 | } 906 | ] 907 | }, 908 | { 909 | "cell_type": "markdown", 910 | "source": [ 911 | "### Oson-6. funcNumber(myList) - myList da musbat va manfiy sonlar berilgan.\n", 912 | "### qaysi turdagi sonlar soni ko'pligini print qiling." 913 | ], 914 | "metadata": { 915 | "collapsed": false, 916 | "pycharm": { 917 | "name": "#%% md\n" 918 | } 919 | } 920 | }, 921 | { 922 | "cell_type": "code", 923 | "source": [ 924 | "def funcNumber(myList):\n", 925 | " res = list(map(lambda x: x > 0, myList))\n", 926 | " return \"Musbat\" if res.count(1) > res.count(0) else \"Manfiy kam emas\"\n", 927 | "\n", 928 | "\n", 929 | "print(funcNumber([1, -22, 3, 3, -3, -3]))" 930 | ], 931 | "metadata": { 932 | "collapsed": false, 933 | "pycharm": { 934 | "name": "#%%\n" 935 | } 936 | }, 937 | "execution_count": 90, 938 | "outputs": [ 939 | { 940 | "name": "stdout", 941 | "output_type": "stream", 942 | "text": [ 943 | "Manfiy kam emas\n" 944 | ] 945 | } 946 | ] 947 | }, 948 | { 949 | "cell_type": "markdown", 950 | "source": [ 951 | "### Qiyin-4. Ikki o'lchovli list berilgan.\n", 952 | "### Masalan: [\n", 953 | "### [4, 9, 3],\n", 954 | "### [5, 2, 6],\n", 955 | "### [8, 1, 7]\n", 956 | "### ]\n", 957 | "### Funksiya elon qiling diagonal(myList, is_reversed)\n", 958 | "### myList - ikki o'lchovli list\n", 959 | "### is_reversed - boolean\n", 960 | "### Agar is_reversed = False bolsa\n", 961 | "### Ikki o'lchovli listni to'gri diagonalini,\n", 962 | "### is_reversed = True bo'lsa teskari diagonalini\n", 963 | "### print qiling.\n", 964 | "### Natija: To'gri diagonal = [4, 2, 7], Teskari diagonal = [3, 2, 8]" 965 | ], 966 | "metadata": { 967 | "collapsed": false 968 | } 969 | }, 970 | { 971 | "cell_type": "code", 972 | "execution_count": 78, 973 | "outputs": [ 974 | { 975 | "name": "stdout", 976 | "output_type": "stream", 977 | "text": [ 978 | "[3, 4, 5]\n" 979 | ] 980 | } 981 | ], 982 | "source": [ 983 | "def diagonal(myList, is_reversed):\n", 984 | " if is_reversed:\n", 985 | " print([myList[i][i] for i in range(len(myList))])\n", 986 | " else:\n", 987 | " print([myList[i][len(myList) - i - 1] for i in range(len(myList))])\n", 988 | "\n", 989 | "\n", 990 | "lst = [\n", 991 | " [1, 2, 3],\n", 992 | " [3, 4, 5],\n", 993 | " [5, 6, 7]\n", 994 | "]\n", 995 | "diagonal(lst, False)" 996 | ], 997 | "metadata": { 998 | "collapsed": false, 999 | "pycharm": { 1000 | "name": "#%%\n" 1001 | } 1002 | } 1003 | }, 1004 | { 1005 | "cell_type": "code", 1006 | "execution_count": null, 1007 | "outputs": [], 1008 | "source": [], 1009 | "metadata": { 1010 | "collapsed": false, 1011 | "pycharm": { 1012 | "name": "#%%\n" 1013 | } 1014 | } 1015 | }, 1016 | { 1017 | "cell_type": "code", 1018 | "execution_count": null, 1019 | "outputs": [], 1020 | "source": [], 1021 | "metadata": { 1022 | "collapsed": false, 1023 | "pycharm": { 1024 | "name": "#%%\n" 1025 | } 1026 | } 1027 | } 1028 | ], 1029 | "metadata": { 1030 | "kernelspec": { 1031 | "display_name": "Python 3", 1032 | "language": "python", 1033 | "name": "python3" 1034 | }, 1035 | "language_info": { 1036 | "codemirror_mode": { 1037 | "name": "ipython", 1038 | "version": 2 1039 | }, 1040 | "file_extension": ".py", 1041 | "mimetype": "text/x-python", 1042 | "name": "python", 1043 | "nbconvert_exporter": "python", 1044 | "pygments_lexer": "ipython2", 1045 | "version": "2.7.6" 1046 | } 1047 | }, 1048 | "nbformat": 4, 1049 | "nbformat_minor": 0 1050 | } -------------------------------------------------------------------------------- /python/12-dars-mehmonxona.py: -------------------------------------------------------------------------------- 1 | mehmonlar = { 2 | "Umidbek": ['19', 'standart'], 3 | "Odiljon": ['17', 'standart'] 4 | } 5 | 6 | 7 | def show(): 8 | print(f"Ismi Xonasi Xona Turi") 9 | for k, v in mehmonlar.items(): 10 | print( 11 | f"{k} {v[0]} {v[1]}" 12 | ) 13 | print('\n\n') 14 | 15 | 16 | def plus(): 17 | ism = input("Ism: ") 18 | 19 | def check(): 20 | xona = input("Xona raqamini kiriting: ") 21 | for k, v in mehmonlar.items(): 22 | if xona == v[0]: 23 | print("Bu xona band, boshqa xona tanlang:\n") 24 | return check() 25 | return xona 26 | 27 | xona = check() 28 | xona_turi = input("Xona turini quyidagi belgilar orqali tanlang:\n" 29 | "\te - ekanom" 30 | "\ts - standart" 31 | "\tl - lyuks") 32 | if xona_turi == 'e': 33 | xona_turi = 'ekanom ' 34 | elif xona_turi == 's': 35 | xona_turi = 'standart ' 36 | if xona_turi == 'l': 37 | xona_turi = 'lyuks ' 38 | mehmonlar[ism] = [xona, xona_turi] 39 | print(f'{ism.title()} mehmonlar ro\'yxatiga qo\'shildi.\n') 40 | 41 | 42 | def minus(): 43 | ism = input("Ism: ") 44 | if ism not in mehmonlar: 45 | print(f"{ism} ismli mehomon yo'q.\n" 46 | f"Iltimos ismni bosqattan kiriting:\n") 47 | return minus() 48 | mehmonlar.pop(ism) 49 | print(f"{ism} mehmonlar ro'yxatidan o'chirildi.\n") 50 | 51 | 52 | def main(): 53 | option = input("Mehmonxonamizga xush kelibsiz!!!\n" 54 | "Buyruqni tanlang:\n" 55 | "1 - Mehmon qo'shish\n" 56 | "2 - Mehmonni ro'yxatdan chiqarish\n" 57 | "3 - Mehmonlar ro'yxati\n\n" 58 | "0 - Dasturdan chiqish\n") 59 | if option == '1': 60 | plus() 61 | elif option == "2": 62 | pass 63 | # minus() 64 | elif option == '3': 65 | show() 66 | elif option == '0': 67 | return 0 68 | return main() 69 | 70 | 71 | main() 72 | -------------------------------------------------------------------------------- /python/13-dars-OPP-1-qism.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "collapsed": true, 7 | "pycharm": { 8 | "name": "#%% md\n" 9 | } 10 | }, 11 | "source": [ 12 | "### Oson1. \"Oson1\" nomli klass elon qililar. Bu klassda \"a\" integer o'zgaruvchi bor.\n", 13 | "### output_a() - bu funksiya klassdagi \"a\" ni qiymatini print qilsin." 14 | ] 15 | }, 16 | { 17 | "cell_type": "code", 18 | "execution_count": 2, 19 | "outputs": [ 20 | { 21 | "name": "stdout", 22 | "output_type": "stream", 23 | "text": [ 24 | "123\n" 25 | ] 26 | } 27 | ], 28 | "source": [ 29 | "class Oson1:\n", 30 | " def __init__(self, a):\n", 31 | " self.a = a\n", 32 | "\n", 33 | " def output_a(self):\n", 34 | " print(self.a)\n", 35 | "\n", 36 | "\n", 37 | "oson = Oson1(123)\n", 38 | "oson.output_a()" 39 | ], 40 | "metadata": { 41 | "collapsed": false, 42 | "pycharm": { 43 | "name": "#%%\n" 44 | } 45 | } 46 | }, 47 | { 48 | "cell_type": "markdown", 49 | "source": [ 50 | "### Oson2. \"Oson2\" nomli klass elon qililar. Bu klassda \"a\" va \"b\" integer o'zgaruvchilari bor.\n", 51 | "### summa() - bu funksiya klassdagi \"a\" va \"b\" ni yig'indisini print qilsin." 52 | ], 53 | "metadata": { 54 | "collapsed": false, 55 | "pycharm": { 56 | "name": "#%% md\n" 57 | } 58 | } 59 | }, 60 | { 61 | "cell_type": "code", 62 | "execution_count": 3, 63 | "outputs": [ 64 | { 65 | "name": "stdout", 66 | "output_type": "stream", 67 | "text": [ 68 | "25\n" 69 | ] 70 | } 71 | ], 72 | "source": [ 73 | "class Oson2:\n", 74 | " def __init__(self, a, b):\n", 75 | " self.a = a\n", 76 | " self.b = b\n", 77 | "\n", 78 | " def summa(self):\n", 79 | " print(self.a + self.b)\n", 80 | "\n", 81 | "\n", 82 | "oson2 = Oson2(12, 13)\n", 83 | "oson2.summa()" 84 | ], 85 | "metadata": { 86 | "collapsed": false, 87 | "pycharm": { 88 | "name": "#%%\n" 89 | } 90 | } 91 | }, 92 | { 93 | "cell_type": "markdown", 94 | "source": [ 95 | "# Oson3. \"Oson3\" nomli klass elon qililar. Bu klassda \"a\" integer o'zgaruvchisi bor.\n", 96 | "# plus_minus() - bu funksiya klassdagi \"a\" ni musbat yoki manfiy ekanligini print qilsin." 97 | ], 98 | "metadata": { 99 | "collapsed": false, 100 | "pycharm": { 101 | "name": "#%% md\n" 102 | } 103 | } 104 | }, 105 | { 106 | "cell_type": "code", 107 | "execution_count": 7, 108 | "outputs": [ 109 | { 110 | "name": "stdout", 111 | "output_type": "stream", 112 | "text": [ 113 | "-12 soni manfiy\n" 114 | ] 115 | } 116 | ], 117 | "source": [ 118 | "class Oson3:\n", 119 | " def __init__(self, a):\n", 120 | " self.a = a\n", 121 | "\n", 122 | " def plus_minus(self):\n", 123 | " print(f\"{self.a} soni {(self.a > 0) * 'musbat'}{(self.a < 0) * 'manfiy'}\")\n", 124 | "\n", 125 | "\n", 126 | "oson3 = Oson3(-12)\n", 127 | "oson3.plus_minus()" 128 | ], 129 | "metadata": { 130 | "collapsed": false, 131 | "pycharm": { 132 | "name": "#%%\n" 133 | } 134 | } 135 | }, 136 | { 137 | "cell_type": "markdown", 138 | "source": [ 139 | "### Oson4. \"Oson4\" nomli klass elon qililar. Bu klassda \"a\" integer o'zgaruvchi bor.\n", 140 | "### odd_even() - bu funksiya klassdagi \"a\" ni to'g yoki juft ekanligini print qilib bersin." 141 | ], 142 | "metadata": { 143 | "collapsed": false, 144 | "pycharm": { 145 | "name": "#%% md\n" 146 | } 147 | } 148 | }, 149 | { 150 | "cell_type": "code", 151 | "execution_count": 10, 152 | "outputs": [ 153 | { 154 | "name": "stdout", 155 | "output_type": "stream", 156 | "text": [ 157 | "12 soni juft son\n" 158 | ] 159 | } 160 | ], 161 | "source": [ 162 | "class Oson4:\n", 163 | " def __init__(self, a):\n", 164 | " self.a = a\n", 165 | "\n", 166 | " def odd_even(self):\n", 167 | " print(f\"{self.a} soni {(self.a % 2 == 1) * 'toq'}{(self.a % 2 == 0) * 'juft'} son\")\n", 168 | "\n", 169 | "\n", 170 | "oson4 = Oson4(12)\n", 171 | "oson4.odd_even()" 172 | ], 173 | "metadata": { 174 | "collapsed": false, 175 | "pycharm": { 176 | "name": "#%%\n" 177 | } 178 | } 179 | }, 180 | { 181 | "cell_type": "markdown", 182 | "source": [ 183 | "### Oson5. \"Oson5\" nomli klass elon qililar. Bu klassda \"a\" va \"b\" integer o'zgaruvchisi bor.\n", 184 | "### daraja() - bu funksiya klassdagi \"a\" ni \"b\" chi darajasini print qilsin." 185 | ], 186 | "metadata": { 187 | "collapsed": false, 188 | "pycharm": { 189 | "name": "#%% md\n" 190 | } 191 | } 192 | }, 193 | { 194 | "cell_type": "code", 195 | "execution_count": 11, 196 | "outputs": [ 197 | { 198 | "name": "stdout", 199 | "output_type": "stream", 200 | "text": [ 201 | "6 ning 3 chi darajasi 216\n" 202 | ] 203 | } 204 | ], 205 | "source": [ 206 | "class Oson5:\n", 207 | " def __init__(self, a, b):\n", 208 | " self.a = a\n", 209 | " self.b = b\n", 210 | "\n", 211 | " def daraja(self):\n", 212 | " print(f\"{self.a} ning {self.b} chi darajasi {self.a ** self.b}\")\n", 213 | "\n", 214 | "\n", 215 | "oson5 = Oson5(6, 3)\n", 216 | "oson5.daraja()" 217 | ], 218 | "metadata": { 219 | "collapsed": false, 220 | "pycharm": { 221 | "name": "#%%\n" 222 | } 223 | } 224 | }, 225 | { 226 | "cell_type": "markdown", 227 | "source": [ 228 | "### 8. \"MyClass8\" nomli klass elon qililar. Bu klassdan \"numbers\" list o'zgaruvchisi bor.\n", 229 | "### compare_lists(new_list) - bu funksiya klassdagi \"numbers\" ni elementlar yig'indisi\n", 230 | "### \"new_list\" ni elementlar yig'indisidan katta aniqlab katta listni print qilsin." 231 | ], 232 | "metadata": { 233 | "collapsed": false, 234 | "pycharm": { 235 | "name": "#%% md\n" 236 | } 237 | } 238 | }, 239 | { 240 | "cell_type": "code", 241 | "execution_count": 15, 242 | "outputs": [ 243 | { 244 | "name": "stdout", 245 | "output_type": "stream", 246 | "text": [ 247 | "[1, 2, 3, 4, 5, 6, 7]\n" 248 | ] 249 | } 250 | ], 251 | "source": [ 252 | "class MyClass8:\n", 253 | " def __init__(self, numbers):\n", 254 | " self.numbers = numbers\n", 255 | "\n", 256 | " def compare_lists(self, new_list):\n", 257 | " print(f\"{(sum(self.numbers) > sum(new_list)) * self.numbers + (sum(self.numbers) < sum(new_list)) * new_list}\")\n", 258 | "\n", 259 | "\n", 260 | "myclass8 = MyClass8([1, 2, 3, 4, 5])\n", 261 | "myclass8.compare_lists([1, 2, 3, 4, 5, 6, 7])\n" 262 | ], 263 | "metadata": { 264 | "collapsed": false, 265 | "pycharm": { 266 | "name": "#%%\n" 267 | } 268 | } 269 | }, 270 | { 271 | "cell_type": "markdown", 272 | "source": [ 273 | "### 10. \"MyClass10\" nomli klass elon qililar. Bu klass \"numbers\" list o'zgaruvchilari bor.\n", 274 | "### divide(d) - bu funksiya klassadagi \"numbers\" list elementlarini \"d\" qoldiqsiz bo'linsa bitta list yig'sin funksiyani ichida.\n", 275 | "### va funksiya oxirida bolinadigonlarni listini return qilsin." 276 | ], 277 | "metadata": { 278 | "collapsed": false, 279 | "pycharm": { 280 | "name": "#%% md\n" 281 | } 282 | } 283 | }, 284 | { 285 | "cell_type": "code", 286 | "execution_count": 9, 287 | "outputs": [ 288 | { 289 | "name": "stdout", 290 | "output_type": "stream", 291 | "text": [ 292 | "[32, 56]\n" 293 | ] 294 | } 295 | ], 296 | "source": [ 297 | "class MyClass10:\n", 298 | " def __init__(self, numbers):\n", 299 | " self.numbers = numbers\n", 300 | "\n", 301 | " def divide(self, d):\n", 302 | " return [num for num in self.numbers if num % d == 0]\n", 303 | "\n", 304 | "\n", 305 | "myclass10 = MyClass10([2, 2, 34, 54, 32, 56, 2, 67])\n", 306 | "print(myclass10.divide(4))" 307 | ], 308 | "metadata": { 309 | "collapsed": false, 310 | "pycharm": { 311 | "name": "#%%\n" 312 | } 313 | } 314 | }, 315 | { 316 | "cell_type": "markdown", 317 | "source": [ 318 | "### vorisdorlik-1:\n", 319 | "### \"Texnika\" parent klass. Konstruktorida esa (brand, model, type) parametrlari bor.\n", 320 | "### info() - (brand, model, type) ni print qilib beradi.\n", 321 | "###\n", 322 | "### \"Notebooks\" child klassi bor. Unda konstruktirida qo'shimcha (video_card, ram, display).\n", 323 | "### more_info() - (brand, model, type, video_card, ram, display) ni print qilib beradi.\n", 324 | "###\n", 325 | "### \"Televisions\" child klassi bor. Unda konstruktirida (size, display) parametrlari bor.\n", 326 | "### more_info() - (brand, model, type, size, display) ni print qilib beradi.\n", 327 | "###\n", 328 | "### \"Smartphones\" child klassi bor. Unda konstruktirida (size, sim_count) parametrlari bor.\n", 329 | "### more_info() - (brand, model, type, size, sim_count) ni print qilib beradi." 330 | ], 331 | "metadata": { 332 | "collapsed": false, 333 | "pycharm": { 334 | "name": "#%% md\n" 335 | } 336 | } 337 | }, 338 | { 339 | "cell_type": "code", 340 | "execution_count": 10, 341 | "outputs": [ 342 | { 343 | "name": "stdout", 344 | "output_type": "stream", 345 | "text": [ 346 | "brand: HP\n", 347 | "model: Pavilion\n", 348 | "type: PC\n" 349 | ] 350 | } 351 | ], 352 | "source": [ 353 | "class Texnika:\n", 354 | " def __init__(self, brand, model, type):\n", 355 | " self.brand = brand\n", 356 | " self.model = model\n", 357 | " self.type = type\n", 358 | "\n", 359 | " def info(self):\n", 360 | " print(f\"brand: {self.brand}\\n\"\n", 361 | " f\"model: {self.model}\\n\"\n", 362 | " f\"type: {self.type}\")\n", 363 | "\n", 364 | "\n", 365 | "texnika = Texnika(\"HP\", 'Pavilion', 'PC')\n", 366 | "texnika.info()" 367 | ], 368 | "metadata": { 369 | "collapsed": false, 370 | "pycharm": { 371 | "name": "#%%\n" 372 | } 373 | } 374 | }, 375 | { 376 | "cell_type": "code", 377 | "execution_count": 11, 378 | "outputs": [ 379 | { 380 | "name": "stdout", 381 | "output_type": "stream", 382 | "text": [ 383 | "brand: HP\n", 384 | "model: Pavilion\n", 385 | "type: PCvideo card: RTX\n", 386 | "ram: 16 GB\n", 387 | "display: 15.6\n", 388 | "\n", 389 | "brand: HP\n", 390 | "model: Pavilion\n", 391 | "type: PC\n" 392 | ] 393 | } 394 | ], 395 | "source": [ 396 | "class Notebooks(Texnika):\n", 397 | " def __init__(self, brand, model, type, video_card, ram, display):\n", 398 | " super().__init__(brand, model, type)\n", 399 | " self.video_card = video_card\n", 400 | " self.ram = ram\n", 401 | " self.display = display\n", 402 | "\n", 403 | " def more_info(self):\n", 404 | " print(f\"brand: {self.brand}\\n\"\n", 405 | " f\"model: {self.model}\\n\"\n", 406 | " f\"type: {self.type}\"\n", 407 | " f\"video card: {self.video_card}\\n\"\n", 408 | " f\"ram: {self.ram}\\n\"\n", 409 | " f\"display: {self.display}\\n\")\n", 410 | "\n", 411 | "\n", 412 | "notebook = Notebooks(\"HP\", \"Pavilion\", \"PC\", \"RTX\", \"16 GB\", \"15.6\")\n", 413 | "notebook.more_info()\n", 414 | "notebook.info()" 415 | ], 416 | "metadata": { 417 | "collapsed": false, 418 | "pycharm": { 419 | "name": "#%%\n" 420 | } 421 | } 422 | }, 423 | { 424 | "cell_type": "code", 425 | "execution_count": 12, 426 | "outputs": [ 427 | { 428 | "name": "stdout", 429 | "output_type": "stream", 430 | "text": [ 431 | "brand: Sasung\n", 432 | "model: Ploskiy\n", 433 | "type: Yupqa\n", 434 | "size: 56\n", 435 | "display: 234\n", 436 | "\n" 437 | ] 438 | } 439 | ], 440 | "source": [ 441 | "class Televisions(Texnika):\n", 442 | " def __init__(self, brand, model, type, size, display):\n", 443 | " super().__init__(brand, model, type)\n", 444 | " self.brand = brand\n", 445 | " self.model = model\n", 446 | " self.type = type\n", 447 | " self.size = size\n", 448 | " self.display = display\n", 449 | "\n", 450 | " def more_info(self):\n", 451 | " print(f\"brand: {self.brand}\\n\"\n", 452 | " f\"model: {self.model}\\n\"\n", 453 | " f\"type: {self.type}\\n\"\n", 454 | " f\"size: {self.size}\\n\"\n", 455 | " f\"display: {self.display}\\n\")\n", 456 | "\n", 457 | "\n", 458 | "televisions = Televisions(\"Sasung\", 'Ploskiy', \"Yupqa\", '56', \"234\")\n", 459 | "televisions.more_info()" 460 | ], 461 | "metadata": { 462 | "collapsed": false, 463 | "pycharm": { 464 | "name": "#%%\n" 465 | } 466 | } 467 | }, 468 | { 469 | "cell_type": "code", 470 | "execution_count": 13, 471 | "outputs": [ 472 | { 473 | "name": "stdout", 474 | "output_type": "stream", 475 | "text": [ 476 | "brand: Redmi\n", 477 | "model: Redmi 9\n", 478 | "type: Smartphone\n", 479 | "size: 32 GB\n", 480 | "sim count: 2\n", 481 | "\n", 482 | "brand: Redmi\n", 483 | "model: Redmi 9\n", 484 | "type: Smartphone\n" 485 | ] 486 | } 487 | ], 488 | "source": [ 489 | "class Smartphones(Texnika):\n", 490 | " def __init__(self, brand, model, type, size, sim_count):\n", 491 | " super().__init__(brand, model, type)\n", 492 | " self.size = size\n", 493 | " self.sim_count = sim_count\n", 494 | "\n", 495 | " def more_info(self):\n", 496 | " print(f\"brand: {self.brand}\\n\"\n", 497 | " f\"model: {self.model}\\n\"\n", 498 | " f\"type: {self.type}\\n\"\n", 499 | " f\"size: {self.size}\\n\"\n", 500 | " f\"sim count: {self.sim_count}\\n\")\n", 501 | "\n", 502 | "\n", 503 | "phone = Smartphones(\"Redmi\", \"Redmi 9\", \"Smartphone\", \"32 GB\", \"2\")\n", 504 | "phone.more_info()\n", 505 | "phone.info()" 506 | ], 507 | "metadata": { 508 | "collapsed": false, 509 | "pycharm": { 510 | "name": "#%%\n" 511 | } 512 | } 513 | }, 514 | { 515 | "cell_type": "markdown", 516 | "source": [ 517 | "### vorisdorlik-2 :\n", 518 | "### \"Transport\" parent klass. Konstruktorida esa (brand, model, type) parametrlari bor.\n", 519 | "### info() - (brand, model, type) ni print qilib beradi.\n", 520 | "###\n", 521 | "### \"ElentroCars\" - child klassi bor. Unda konstruktirida qo'shimcha (battery_life, chargin_time).\n", 522 | "### more_info() - (brand, model, type, battery_life, chargin_time) ni print qilib beradi.\n", 523 | "###\n", 524 | "### \"SportCars\" - child klassi bor. Unda konstruktirida qo'shimcha (motor, color).\n", 525 | "### more_info() - (brand, model, type, motor, color) ni print qilib beradi.\n", 526 | "###\n", 527 | "### \"Truck\" - child klassi bor. Unda konstruktirida qo'shimcha (motor, height, long, wieght).\n", 528 | "### more_info() - (brand, model, type, height, long, wieght) ni print qilib beradi." 529 | ], 530 | "metadata": { 531 | "collapsed": false, 532 | "pycharm": { 533 | "name": "#%% md\n" 534 | } 535 | } 536 | }, 537 | { 538 | "cell_type": "code", 539 | "execution_count": 14, 540 | "outputs": [ 541 | { 542 | "name": "stdout", 543 | "output_type": "stream", 544 | "text": [ 545 | "brand: GM\n", 546 | "model: Nexia 3\n", 547 | "type: Yengil\n", 548 | "\n" 549 | ] 550 | } 551 | ], 552 | "source": [ 553 | "class Transport:\n", 554 | " def __init__(self, brand, model, type):\n", 555 | " self.brand = brand\n", 556 | " self.model = model\n", 557 | " self.type = type\n", 558 | "\n", 559 | " def info(self):\n", 560 | " print(f\"brand: {self.brand}\\n\"\n", 561 | " f\"model: {self.model}\\n\"\n", 562 | " f\"type: {self.type}\\n\")\n", 563 | "\n", 564 | "\n", 565 | "transport = Transport(\"GM\", 'Nexia 3', 'Yengil')\n", 566 | "transport.info()" 567 | ], 568 | "metadata": { 569 | "collapsed": false, 570 | "pycharm": { 571 | "name": "#%%\n" 572 | } 573 | } 574 | }, 575 | { 576 | "cell_type": "code", 577 | "execution_count": 16, 578 | "outputs": [ 579 | { 580 | "name": "stdout", 581 | "output_type": "stream", 582 | "text": [ 583 | "brand: Tesla\n", 584 | "model: UMS\n", 585 | "type: Electro\n", 586 | "battery life: 450 km\n", 587 | "chargin time: 12 hours\n", 588 | "\n" 589 | ] 590 | } 591 | ], 592 | "source": [ 593 | "class ElentroCars(Transport):\n", 594 | " def __init__(self, brand, model, type, battery_life, chargin_time):\n", 595 | " super().__init__(brand, model, type)\n", 596 | " self.battery_life = battery_life\n", 597 | " self.chargin_time = chargin_time\n", 598 | "\n", 599 | " def more_info(self):\n", 600 | " print(f\"brand: {self.brand}\\n\"\n", 601 | " f\"model: {self.model}\\n\"\n", 602 | " f\"type: {self.type}\\n\"\n", 603 | " f\"battery life: {self.battery_life}\\n\"\n", 604 | " f\"chargin time: {self.chargin_time}\\n\")\n", 605 | "\n", 606 | "\n", 607 | "elentrocars = ElentroCars(\"Tesla\", \"UMS\", \"Electro\", \"450 km\", \"12 hours\")\n", 608 | "elentrocars.more_info()" 609 | ], 610 | "metadata": { 611 | "collapsed": false, 612 | "pycharm": { 613 | "name": "#%%\n" 614 | } 615 | } 616 | }, 617 | { 618 | "cell_type": "code", 619 | "execution_count": 17, 620 | "outputs": [ 621 | { 622 | "name": "stdout", 623 | "output_type": "stream", 624 | "text": [ 625 | "brand: Ferrari\n", 626 | "model: Bens\n", 627 | "type: Sportcar\n", 628 | "motor: 3450 k\n", 629 | "color: red\n", 630 | "\n" 631 | ] 632 | } 633 | ], 634 | "source": [ 635 | "class SportCars(Transport):\n", 636 | " def __init__(self, brand, model, type, motor, color):\n", 637 | " super().__init__(brand, model, type)\n", 638 | " self.motor = motor\n", 639 | " self.color = color\n", 640 | "\n", 641 | " def more_info(self):\n", 642 | " print(f\"brand: {self.brand}\\n\"\n", 643 | " f\"model: {self.model}\\n\"\n", 644 | " f\"type: {self.type}\\n\"\n", 645 | " f\"motor: {self.motor}\\n\"\n", 646 | " f\"color: {self.color}\\n\")\n", 647 | "\n", 648 | "\n", 649 | "sportcar = SportCars(\"Ferrari\", \"Bens\", 'Sportcar', \"3450 k\", \"red\")\n", 650 | "sportcar.more_info()" 651 | ], 652 | "metadata": { 653 | "collapsed": false, 654 | "pycharm": { 655 | "name": "#%%\n" 656 | } 657 | } 658 | }, 659 | { 660 | "cell_type": "code", 661 | "execution_count": 19, 662 | "outputs": [ 663 | { 664 | "name": "stdout", 665 | "output_type": "stream", 666 | "text": [ 667 | "brand: MAN\n", 668 | "model: Isuzi\n", 669 | "type: Katta\n", 670 | "motor: 23400\n", 671 | "height: 23 m\n", 672 | "long: 6 m\n", 673 | "wieght: 12 t\n" 674 | ] 675 | } 676 | ], 677 | "source": [ 678 | "class Truck(Transport):\n", 679 | " def __init__(self, brand, model, type, motor, height, long, wieght):\n", 680 | " super().__init__(brand, model, type)\n", 681 | " self.motor = motor\n", 682 | " self.height = height\n", 683 | " self.long = long\n", 684 | " self.wieght = wieght\n", 685 | "\n", 686 | " def more_info(self):\n", 687 | " print(f\"brand: {self.brand}\\n\"\n", 688 | " f\"model: {self.model}\\n\"\n", 689 | " f\"type: {self.type}\\n\"\n", 690 | " f\"motor: {self.motor}\\n\"\n", 691 | " f\"height: {self.height}\\n\"\n", 692 | " f\"long: {self.long}\\n\"\n", 693 | " f\"wieght: {self.wieght}\")\n", 694 | "\n", 695 | "\n", 696 | "truck = Truck(\"MAN\", \"Isuzi\", \"Katta\", \"23400\", \"23 m\", \"6 m\", '12 t')\n", 697 | "truck.more_info()" 698 | ], 699 | "metadata": { 700 | "collapsed": false, 701 | "pycharm": { 702 | "name": "#%%\n" 703 | } 704 | } 705 | }, 706 | { 707 | "cell_type": "markdown", 708 | "source": [], 709 | "metadata": { 710 | "collapsed": false, 711 | "pycharm": { 712 | "name": "#%% md\n" 713 | } 714 | } 715 | } 716 | ], 717 | "metadata": { 718 | "kernelspec": { 719 | "display_name": "Python 3", 720 | "language": "python", 721 | "name": "python3" 722 | }, 723 | "language_info": { 724 | "codemirror_mode": { 725 | "name": "ipython", 726 | "version": 2 727 | }, 728 | "file_extension": ".py", 729 | "mimetype": "text/x-python", 730 | "name": "python", 731 | "nbconvert_exporter": "python", 732 | "pygments_lexer": "ipython2", 733 | "version": "2.7.6" 734 | } 735 | }, 736 | "nbformat": 4, 737 | "nbformat_minor": 0 738 | } -------------------------------------------------------------------------------- /python/14-Polimorfizm-Paket-modul/paket1/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-Umidjon/Backend-django/685bb79d2022109a19e09aff3f6afbf841a805d1/python/14-Polimorfizm-Paket-modul/paket1/__init__.py -------------------------------------------------------------------------------- /python/14-Polimorfizm-Paket-modul/paket1/modul1.py: -------------------------------------------------------------------------------- 1 | from modul2 import count_letter 2 | 3 | k = count_letter('Maxammadsoliyev', 'm') 4 | 5 | print(k) 6 | -------------------------------------------------------------------------------- /python/14-Polimorfizm-Paket-modul/paket1/modul2.py: -------------------------------------------------------------------------------- 1 | def count_letter(word, letter): 2 | "Bu funksiya wordni ichida nechta letter bor ekanligni returni qiladi." 3 | k = 0 4 | for i in word: 5 | if i == letter: 6 | k += 1 7 | return k 8 | -------------------------------------------------------------------------------- /python/14-Polimorfizm-Paket-modul/paket2/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-Umidjon/Backend-django/685bb79d2022109a19e09aff3f6afbf841a805d1/python/14-Polimorfizm-Paket-modul/paket2/__init__.py -------------------------------------------------------------------------------- /python/14-Polimorfizm-Paket-modul/paket2/modul1.py: -------------------------------------------------------------------------------- 1 | from modul2 import max_elem, min_elem 2 | 3 | lst = [1, 4, 5, 8, 9] 4 | minElem = min_elem(lst) 5 | maxElem = max_elem(lst) 6 | 7 | print(f"Min: {minElem}\nMax: {maxElem}") 8 | -------------------------------------------------------------------------------- /python/14-Polimorfizm-Paket-modul/paket2/modul2.py: -------------------------------------------------------------------------------- 1 | def max_elem(myList): 2 | """myListni ichidan maximumni topib returni qiladi.""" 3 | return max(myList) 4 | 5 | 6 | def min_elem(myList): 7 | """myListni ichidan minimumni topib returni qiladi.""" 8 | return min(myList) -------------------------------------------------------------------------------- /python/14-Polimorfizm-Paket-modul/paket3/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-Umidjon/Backend-django/685bb79d2022109a19e09aff3f6afbf841a805d1/python/14-Polimorfizm-Paket-modul/paket3/__init__.py -------------------------------------------------------------------------------- /python/14-Polimorfizm-Paket-modul/paket3/add.py: -------------------------------------------------------------------------------- 1 | def add_numbers(a, b): 2 | """Bu funksiya a va b yig'indisini return qiladi.""" 3 | return a + b 4 | -------------------------------------------------------------------------------- /python/14-Polimorfizm-Paket-modul/paket3/div.py: -------------------------------------------------------------------------------- 1 | def div_numbers(a, b): 2 | """Bu funksiya a / b natijasini return qiladi.""" 3 | return a / b 4 | -------------------------------------------------------------------------------- /python/14-Polimorfizm-Paket-modul/paket3/mul.py: -------------------------------------------------------------------------------- 1 | def mul_numbers(a, b): 2 | """Bu funksiya a ni b ga ko'paytmasini return qiladi.""" 3 | return a * b 4 | -------------------------------------------------------------------------------- /python/14-Polimorfizm-Paket-modul/paket3/result.py: -------------------------------------------------------------------------------- 1 | ### x = ((i + j)*(j+45))/(10-i) 2 | 3 | from add import add_numbers 4 | from sub import sub_numbers 5 | from mul import mul_numbers 6 | from div import div_numbers 7 | 8 | i = float(input("I = ")) 9 | j = float(input("J = ")) 10 | 11 | x = div_numbers(mul_numbers(add_numbers(i, j), add_numbers(j, 45)), sub_numbers(10, i)) 12 | print(x) 13 | print(((i + j)*(j+45))/(10-i)) 14 | -------------------------------------------------------------------------------- /python/14-Polimorfizm-Paket-modul/paket3/sub.py: -------------------------------------------------------------------------------- 1 | def sub_numbers(a, b): 2 | """Bu funksiya a va b ayirmasini return qiladi.""" 3 | return a - b 4 | -------------------------------------------------------------------------------- /python/14-dars-Math-Datetime.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "collapsed": true, 7 | "pycharm": { 8 | "name": "#%% md\n" 9 | } 10 | }, 11 | "source": [ 12 | "### Exercise 1: Print current date and time in Python" 13 | ] 14 | }, 15 | { 16 | "cell_type": "code", 17 | "execution_count": 3, 18 | "outputs": [ 19 | { 20 | "name": "stdout", 21 | "output_type": "stream", 22 | "text": [ 23 | "2022-04-22 00:40:21.874153\n", 24 | "00:40:21.874153\n" 25 | ] 26 | } 27 | ], 28 | "source": [ 29 | "from datetime import datetime\n", 30 | "\n", 31 | "# 1 - usul\n", 32 | "# sana va vaqt\n", 33 | "print(datetime.now())\n", 34 | "\n", 35 | "# faqat vaqt\n", 36 | "print(datetime.now().time())" 37 | ], 38 | "metadata": { 39 | "collapsed": false, 40 | "pycharm": { 41 | "name": "#%%\n" 42 | } 43 | } 44 | }, 45 | { 46 | "cell_type": "markdown", 47 | "source": [ 48 | "### Exercise 2: Convert string into a datetime object" 49 | ], 50 | "metadata": { 51 | "collapsed": false, 52 | "pycharm": { 53 | "name": "#%% md\n" 54 | } 55 | } 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": 10, 60 | "outputs": [ 61 | { 62 | "name": "stdout", 63 | "output_type": "stream", 64 | "text": [ 65 | "2020-02-25 16:20:00\n" 66 | ] 67 | } 68 | ], 69 | "source": [ 70 | "from datetime import datetime\n", 71 | "\n", 72 | "date_string = \"Feb 25 2020 4:20PM\"\n", 73 | "\n", 74 | "data_object = datetime.strptime(date_string, \"%b %d %Y %I:%M%p\")\n", 75 | "print(data_object)" 76 | ], 77 | "metadata": { 78 | "collapsed": false, 79 | "pycharm": { 80 | "name": "#%%\n" 81 | } 82 | } 83 | }, 84 | { 85 | "cell_type": "markdown", 86 | "source": [ 87 | "### Exercise 3: Subtract a week (7 days) from a given date in Python" 88 | ], 89 | "metadata": { 90 | "collapsed": false, 91 | "pycharm": { 92 | "name": "#%% md\n" 93 | } 94 | } 95 | }, 96 | { 97 | "cell_type": "code", 98 | "execution_count": 13, 99 | "outputs": [ 100 | { 101 | "name": "stdout", 102 | "output_type": "stream", 103 | "text": [ 104 | "2020-02-18 00:00:00\n" 105 | ] 106 | } 107 | ], 108 | "source": [ 109 | "from datetime import datetime, timedelta\n", 110 | "\n", 111 | "given_date = datetime(2020, 2, 25)\n", 112 | "res_date = given_date - timedelta(weeks=1)\n", 113 | "# res_date = given_date - timedelta(days=7)\n", 114 | "print(res_date)" 115 | ], 116 | "metadata": { 117 | "collapsed": false, 118 | "pycharm": { 119 | "name": "#%%\n" 120 | } 121 | } 122 | }, 123 | { 124 | "cell_type": "markdown", 125 | "source": [ 126 | "### Exercise 4: Print a date in a the following format" 127 | ], 128 | "metadata": { 129 | "collapsed": false, 130 | "pycharm": { 131 | "name": "#%% md\n" 132 | } 133 | } 134 | }, 135 | { 136 | "cell_type": "code", 137 | "execution_count": 22, 138 | "outputs": [ 139 | { 140 | "name": "stdout", 141 | "output_type": "stream", 142 | "text": [ 143 | "Tuesday 25 February 2020\n" 144 | ] 145 | } 146 | ], 147 | "source": [ 148 | "from datetime import datetime\n", 149 | "\n", 150 | "given_date = datetime(2020, 2, 25)\n", 151 | "\n", 152 | "# Tuesday 25 February 2020\n", 153 | "\n", 154 | "res_date = datetime.strftime(given_date, \"%A %d %B %Y\")\n", 155 | "print(res_date)" 156 | ], 157 | "metadata": { 158 | "collapsed": false, 159 | "pycharm": { 160 | "name": "#%%\n" 161 | } 162 | } 163 | }, 164 | { 165 | "cell_type": "markdown", 166 | "source": [ 167 | "### Exercise 5: Find the day of the week of a given date" 168 | ], 169 | "metadata": { 170 | "collapsed": false, 171 | "pycharm": { 172 | "name": "#%% md\n" 173 | } 174 | } 175 | }, 176 | { 177 | "cell_type": "code", 178 | "execution_count": 28, 179 | "outputs": [ 180 | { 181 | "name": "stdout", 182 | "output_type": "stream", 183 | "text": [ 184 | "Sunday\n", 185 | "Sunday\n" 186 | ] 187 | } 188 | ], 189 | "source": [ 190 | "given_date = datetime(2020, 7, 26)\n", 191 | "\n", 192 | "print(datetime.strftime(given_date, \"%A\"))\n", 193 | "# print(given_date.today().weekday())\n", 194 | "print(given_date.strftime(\"%A\"))" 195 | ], 196 | "metadata": { 197 | "collapsed": false, 198 | "pycharm": { 199 | "name": "#%%\n" 200 | } 201 | } 202 | }, 203 | { 204 | "cell_type": "markdown", 205 | "source": [ 206 | "### Exercise 6: Add a week (7 days) and 12 hours to a given date" 207 | ], 208 | "metadata": { 209 | "collapsed": false, 210 | "pycharm": { 211 | "name": "#%% md\n" 212 | } 213 | } 214 | }, 215 | { 216 | "cell_type": "code", 217 | "execution_count": 29, 218 | "outputs": [ 219 | { 220 | "name": "stdout", 221 | "output_type": "stream", 222 | "text": [ 223 | "2020-03-29 22:00:00\n" 224 | ] 225 | } 226 | ], 227 | "source": [ 228 | "from datetime import datetime, timedelta\n", 229 | "\n", 230 | "# 2020-03-22 10:00:00\n", 231 | "given_date = datetime(2020, 3, 22, 10, 0, 0)\n", 232 | "\n", 233 | "res_date = given_date + timedelta(days=7, hours=12)\n", 234 | "print(res_date)\n", 235 | "# 2020-03-29 22:00:00" 236 | ], 237 | "metadata": { 238 | "collapsed": false, 239 | "pycharm": { 240 | "name": "#%%\n" 241 | } 242 | } 243 | }, 244 | { 245 | "cell_type": "markdown", 246 | "source": [ 247 | "### Exercise 7: Print current time in milliseconds" 248 | ], 249 | "metadata": { 250 | "collapsed": false, 251 | "pycharm": { 252 | "name": "#%% md\n" 253 | } 254 | } 255 | }, 256 | { 257 | "cell_type": "code", 258 | "execution_count": 37, 259 | "outputs": [ 260 | { 261 | "name": "stdout", 262 | "output_type": "stream", 263 | "text": [ 264 | "1650571571716\n" 265 | ] 266 | } 267 | ], 268 | "source": [ 269 | "import time\n", 270 | "\n", 271 | "milliseconds = int(round(time.time() * 1000))\n", 272 | "print(milliseconds)" 273 | ], 274 | "metadata": { 275 | "collapsed": false, 276 | "pycharm": { 277 | "name": "#%%\n" 278 | } 279 | } 280 | }, 281 | { 282 | "cell_type": "markdown", 283 | "source": [ 284 | "### Exercise 8: Convert the following datetime into a string" 285 | ], 286 | "metadata": { 287 | "collapsed": false, 288 | "pycharm": { 289 | "name": "#%% md\n" 290 | } 291 | } 292 | }, 293 | { 294 | "cell_type": "code", 295 | "execution_count": 45, 296 | "outputs": [ 297 | { 298 | "name": "stdout", 299 | "output_type": "stream", 300 | "text": [ 301 | "2020-02-25 00:00:00\n" 302 | ] 303 | } 304 | ], 305 | "source": [ 306 | "given_date = datetime(2020, 2, 25)\n", 307 | "\n", 308 | "date_string = given_date.strftime(\"%Y-%m-%d %H:%M:%S\")\n", 309 | "print(date_string)\n", 310 | "# \"2020-02-25 00:00:00\"" 311 | ], 312 | "metadata": { 313 | "collapsed": false, 314 | "pycharm": { 315 | "name": "#%%\n" 316 | } 317 | } 318 | }, 319 | { 320 | "cell_type": "markdown", 321 | "source": [ 322 | "### Exercise 9: Calculate the date 4 months from the current date" 323 | ], 324 | "metadata": { 325 | "collapsed": false, 326 | "pycharm": { 327 | "name": "#%% md\n" 328 | } 329 | } 330 | }, 331 | { 332 | "cell_type": "code", 333 | "execution_count": 50, 334 | "outputs": [ 335 | { 336 | "name": "stdout", 337 | "output_type": "stream", 338 | "text": [ 339 | "2020-02-25\n", 340 | "2020-06-25\n" 341 | ] 342 | } 343 | ], 344 | "source": [ 345 | "from datetime import datetime\n", 346 | "from dateutil.relativedelta import relativedelta\n", 347 | "\n", 348 | "# 2020-02-25\n", 349 | "given_date = datetime(2020, 2, 25).date()\n", 350 | "print(given_date)\n", 351 | "\n", 352 | "res_date = given_date + relativedelta(months=4)\n", 353 | "print(res_date)\n", 354 | "# 2020-06-25" 355 | ], 356 | "metadata": { 357 | "collapsed": false, 358 | "pycharm": { 359 | "name": "#%%\n" 360 | } 361 | } 362 | }, 363 | { 364 | "cell_type": "markdown", 365 | "source": [ 366 | "### Exercise 10: Calculate number of days between two given dates" 367 | ], 368 | "metadata": { 369 | "collapsed": false, 370 | "pycharm": { 371 | "name": "#%% md\n" 372 | } 373 | } 374 | }, 375 | { 376 | "cell_type": "code", 377 | "execution_count": 59, 378 | "outputs": [ 379 | { 380 | "name": "stdout", 381 | "output_type": "stream", 382 | "text": [ 383 | "205 days\n" 384 | ] 385 | } 386 | ], 387 | "source": [ 388 | "from datetime import datetime\n", 389 | "from dateutil.relativedelta import relativedelta\n", 390 | "\n", 391 | "# 2020-02-25\n", 392 | "date_1 = datetime(2020, 2, 25).date()\n", 393 | "\n", 394 | "# 2020-09-17\n", 395 | "date_2 = datetime(2020, 9, 17).date()\n", 396 | "\n", 397 | "if date_2 > date_1:\n", 398 | " days = date_2 - date_1\n", 399 | "else:\n", 400 | " days = date_1 - date_2\n", 401 | "\n", 402 | "print(days.days, \"days\")" 403 | ], 404 | "metadata": { 405 | "collapsed": false, 406 | "pycharm": { 407 | "name": "#%%\n" 408 | } 409 | } 410 | }, 411 | { 412 | "cell_type": "code", 413 | "execution_count": null, 414 | "outputs": [], 415 | "source": [], 416 | "metadata": { 417 | "collapsed": false, 418 | "pycharm": { 419 | "name": "#%%\n" 420 | } 421 | } 422 | } 423 | ], 424 | "metadata": { 425 | "kernelspec": { 426 | "display_name": "Python 3", 427 | "language": "python", 428 | "name": "python3" 429 | }, 430 | "language_info": { 431 | "codemirror_mode": { 432 | "name": "ipython", 433 | "version": 2 434 | }, 435 | "file_extension": ".py", 436 | "mimetype": "text/x-python", 437 | "name": "python", 438 | "nbconvert_exporter": "python", 439 | "pygments_lexer": "ipython2", 440 | "version": "2.7.6" 441 | } 442 | }, 443 | "nbformat": 4, 444 | "nbformat_minor": 0 445 | } -------------------------------------------------------------------------------- /python/14-dars-OOP-2-qism.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "collapsed": true, 7 | "pycharm": { 8 | "name": "#%% md\n" 9 | } 10 | }, 11 | "source": [ 12 | "### 1. \"Texnika\" parent klass. Konstruktorida esa (brand, model, type) parametrlari bor.\n", 13 | "### info() - (brand, model, type) ni print qilib beradi.\n", 14 | "###\n", 15 | "### \"Notebooks\" child klassi bor. Unda konstruktirida qo'shimcha (video_card, ram, display).\n", 16 | "### more_info() - (brand, model, type, video_card, ram, display) ni print qilib beradi.\n", 17 | "###\n", 18 | "### \"Televisions\" child klassi bor. Unda konstruktirida (size, display) parametrlari bor.\n", 19 | "### more_info() - (brand, model, type, size, display) ni print qilib beradi.\n", 20 | "###\n", 21 | "### \"Smartphones\" child klassi bor. Unda konstruktirida (size, sim_count) parametrlari bor.\n", 22 | "### more_info() - (brand, model, type, size, sim_count) ni print qilib beradi." 23 | ] 24 | }, 25 | { 26 | "cell_type": "code", 27 | "execution_count": 1, 28 | "outputs": [ 29 | { 30 | "name": "stdout", 31 | "output_type": "stream", 32 | "text": [ 33 | "brand: REDMI\n", 34 | "model: Redmi 9\n", 35 | "type: Phone\n" 36 | ] 37 | } 38 | ], 39 | "source": [ 40 | "class Texnika:\n", 41 | " def __init__(self, brand, model, type):\n", 42 | " self.brand = brand\n", 43 | " self.model = model\n", 44 | " self.type = type\n", 45 | "\n", 46 | " def info(self):\n", 47 | " print(f\"brand: {self.brand}\\n\"\n", 48 | " f\"model: {self.model}\\n\"\n", 49 | " f\"type: {self.type}\")\n", 50 | "\n", 51 | "\n", 52 | "texnika = Texnika(\"REDMI\", \"Redmi 9\", 'Phone')\n", 53 | "texnika.info()" 54 | ], 55 | "metadata": { 56 | "collapsed": false, 57 | "pycharm": { 58 | "name": "#%%\n" 59 | } 60 | } 61 | }, 62 | { 63 | "cell_type": "code", 64 | "execution_count": 2, 65 | "outputs": [ 66 | { 67 | "name": "stdout", 68 | "output_type": "stream", 69 | "text": [ 70 | "brand: HP\n", 71 | "model: Pavilion\n", 72 | "type: PC\n", 73 | "video card: RTX\n", 74 | "ram: 8 GB\n", 75 | "display: 15.6\n" 76 | ] 77 | } 78 | ], 79 | "source": [ 80 | "class Notebooks(Texnika):\n", 81 | " def __init__(self, brand, model, type, video_card, ram, display):\n", 82 | " super().__init__(brand, model, type)\n", 83 | " self.video_card = video_card\n", 84 | " self.ram = ram\n", 85 | " self.display = display\n", 86 | "\n", 87 | " def more_info(self):\n", 88 | " print(f\"brand: {self.brand}\\n\"\n", 89 | " f\"model: {self.model}\\n\"\n", 90 | " f\"type: {self.type}\\n\"\n", 91 | " f\"video card: {self.video_card}\\n\"\n", 92 | " f\"ram: {self.ram}\\n\"\n", 93 | " f\"display: {self.display}\")\n", 94 | "\n", 95 | "\n", 96 | "pc = Notebooks(\"HP\", \"Pavilion\", \"PC\", 'RTX', \"8 GB\", \"15.6\")\n", 97 | "pc.more_info()" 98 | ], 99 | "metadata": { 100 | "collapsed": false, 101 | "pycharm": { 102 | "name": "#%%\n" 103 | } 104 | } 105 | }, 106 | { 107 | "cell_type": "code", 108 | "execution_count": 4, 109 | "outputs": [ 110 | { 111 | "name": "stdout", 112 | "output_type": "stream", 113 | "text": [ 114 | "brand: Samsung\n", 115 | "model: SmartTv\n", 116 | "type: Smart\n", 117 | "size: 45\n", 118 | "display: 35.6\n" 119 | ] 120 | } 121 | ], 122 | "source": [ 123 | "class Televisions(Texnika):\n", 124 | " def __init__(self, brand, model, type, size, display):\n", 125 | " super().__init__(brand, model, type)\n", 126 | " self.size = size\n", 127 | " self.display = display\n", 128 | "\n", 129 | " def more_info(self):\n", 130 | " print(f\"brand: {self.brand}\\n\"\n", 131 | " f\"model: {self.model}\\n\"\n", 132 | " f\"type: {self.type}\\n\"\n", 133 | " f\"size: {self.size}\\n\"\n", 134 | " f\"display: {self.display}\")\n", 135 | "\n", 136 | "\n", 137 | "tv = Televisions(\"Samsung\", \"SmartTv\", \"Smart\", \"45\", \"35.6\")\n", 138 | "tv.more_info()" 139 | ], 140 | "metadata": { 141 | "collapsed": false, 142 | "pycharm": { 143 | "name": "#%%\n" 144 | } 145 | } 146 | }, 147 | { 148 | "cell_type": "code", 149 | "execution_count": 5, 150 | "outputs": [ 151 | { 152 | "name": "stdout", 153 | "output_type": "stream", 154 | "text": [ 155 | "brand: Redmi\n", 156 | "model: Redmi 9\n", 157 | "type: Smartphone\n", 158 | "size: 32 GB\n", 159 | "sim count: 2\n", 160 | "\n", 161 | "brand: Redmi\n", 162 | "model: Redmi 9\n", 163 | "type: Smartphone\n" 164 | ] 165 | } 166 | ], 167 | "source": [ 168 | "class Smartphones(Texnika):\n", 169 | " def __init__(self, brand, model, type, size, sim_count):\n", 170 | " super().__init__(brand, model, type)\n", 171 | " self.size = size\n", 172 | " self.sim_count = sim_count\n", 173 | "\n", 174 | " def more_info(self):\n", 175 | " print(f\"brand: {self.brand}\\n\"\n", 176 | " f\"model: {self.model}\\n\"\n", 177 | " f\"type: {self.type}\\n\"\n", 178 | " f\"size: {self.size}\\n\"\n", 179 | " f\"sim count: {self.sim_count}\\n\")\n", 180 | "\n", 181 | "\n", 182 | "phone = Smartphones(\"Redmi\", \"Redmi 9\", \"Smartphone\", \"32 GB\", \"2\")\n", 183 | "phone.more_info()\n", 184 | "phone.info()" 185 | ], 186 | "metadata": { 187 | "collapsed": false, 188 | "pycharm": { 189 | "name": "#%%\n" 190 | } 191 | } 192 | }, 193 | { 194 | "cell_type": "markdown", 195 | "source": [ 196 | "### 2. \"Transport\" parent klass. Konstruktorida esa (brand, model, type) parametrlari bor.\n", 197 | "### info() - (brand, model, type) ni print qilib beradi.\n", 198 | "###\n", 199 | "### \"ElentroCars\" - child klassi bor. Unda konstruktirida qo'shimcha (battery_life, chargin_time).\n", 200 | "### more_info() - (brand, model, type, battery_life, chargin_time) ni print qilib beradi.\n", 201 | "###\n", 202 | "### \"SportCars\" - child klassi bor. Unda konstruktirida qo'shimcha (motor, color).\n", 203 | "### more_info() - (brand, model, type, motor, color) ni print qilib beradi.\n", 204 | "###\n", 205 | "### \"Truck\" - child klassi bor. Unda konstruktirida qo'shimcha (motor, height, long, wieght).\n", 206 | "### more_info() - (brand, model, type, height, long, wieght) ni print qilib beradi." 207 | ], 208 | "metadata": { 209 | "collapsed": false, 210 | "pycharm": { 211 | "name": "#%% md\n" 212 | } 213 | } 214 | }, 215 | { 216 | "cell_type": "code", 217 | "execution_count": 6, 218 | "outputs": [ 219 | { 220 | "name": "stdout", 221 | "output_type": "stream", 222 | "text": [ 223 | "brand: GM\n", 224 | "model: Nexia 3\n", 225 | "type: Yengil\n", 226 | "\n" 227 | ] 228 | } 229 | ], 230 | "source": [ 231 | "class Transport:\n", 232 | " def __init__(self, brand, model, type):\n", 233 | " self.brand = brand\n", 234 | " self.model = model\n", 235 | " self.type = type\n", 236 | "\n", 237 | " def info(self):\n", 238 | " print(f\"brand: {self.brand}\\n\"\n", 239 | " f\"model: {self.model}\\n\"\n", 240 | " f\"type: {self.type}\\n\")\n", 241 | "\n", 242 | "\n", 243 | "transport = Transport(\"GM\", 'Nexia 3', 'Yengil')\n", 244 | "transport.info()" 245 | ], 246 | "metadata": { 247 | "collapsed": false, 248 | "pycharm": { 249 | "name": "#%%\n" 250 | } 251 | } 252 | }, 253 | { 254 | "cell_type": "code", 255 | "execution_count": 7, 256 | "outputs": [ 257 | { 258 | "name": "stdout", 259 | "output_type": "stream", 260 | "text": [ 261 | "brand: Tesla\n", 262 | "model: UMS\n", 263 | "type: Electro\n", 264 | "battery life: 450 km\n", 265 | "chargin time: 12 hours\n", 266 | "\n" 267 | ] 268 | } 269 | ], 270 | "source": [ 271 | "class ElentroCars(Transport):\n", 272 | " def __init__(self, brand, model, type, battery_life, chargin_time):\n", 273 | " super().__init__(brand, model, type)\n", 274 | " self.battery_life = battery_life\n", 275 | " self.chargin_time = chargin_time\n", 276 | "\n", 277 | " def more_info(self):\n", 278 | " print(f\"brand: {self.brand}\\n\"\n", 279 | " f\"model: {self.model}\\n\"\n", 280 | " f\"type: {self.type}\\n\"\n", 281 | " f\"battery life: {self.battery_life}\\n\"\n", 282 | " f\"chargin time: {self.chargin_time}\\n\")\n", 283 | "\n", 284 | "\n", 285 | "elentrocars = ElentroCars(\"Tesla\", \"UMS\", \"Electro\", \"450 km\", \"12 hours\")\n", 286 | "elentrocars.more_info()" 287 | ], 288 | "metadata": { 289 | "collapsed": false, 290 | "pycharm": { 291 | "name": "#%%\n" 292 | } 293 | } 294 | }, 295 | { 296 | "cell_type": "code", 297 | "execution_count": 8, 298 | "outputs": [ 299 | { 300 | "name": "stdout", 301 | "output_type": "stream", 302 | "text": [ 303 | "brand: Ferrari\n", 304 | "model: Bens\n", 305 | "type: Sportcar\n", 306 | "motor: 3450 k\n", 307 | "color: red\n", 308 | "\n" 309 | ] 310 | } 311 | ], 312 | "source": [ 313 | "class SportCars(Transport):\n", 314 | " def __init__(self, brand, model, type, motor, color):\n", 315 | " super().__init__(brand, model, type)\n", 316 | " self.motor = motor\n", 317 | " self.color = color\n", 318 | "\n", 319 | " def more_info(self):\n", 320 | " print(f\"brand: {self.brand}\\n\"\n", 321 | " f\"model: {self.model}\\n\"\n", 322 | " f\"type: {self.type}\\n\"\n", 323 | " f\"motor: {self.motor}\\n\"\n", 324 | " f\"color: {self.color}\\n\")\n", 325 | "\n", 326 | "\n", 327 | "sportcar = SportCars(\"Ferrari\", \"Bens\", 'Sportcar', \"3450 k\", \"red\")\n", 328 | "sportcar.more_info()" 329 | ], 330 | "metadata": { 331 | "collapsed": false, 332 | "pycharm": { 333 | "name": "#%%\n" 334 | } 335 | } 336 | }, 337 | { 338 | "cell_type": "code", 339 | "execution_count": 9, 340 | "outputs": [ 341 | { 342 | "name": "stdout", 343 | "output_type": "stream", 344 | "text": [ 345 | "brand: MAN\n", 346 | "model: Isuzi\n", 347 | "type: Katta\n", 348 | "motor: 23400\n", 349 | "height: 23 m\n", 350 | "long: 6 m\n", 351 | "wieght: 12 t\n" 352 | ] 353 | } 354 | ], 355 | "source": [ 356 | "class Truck(Transport):\n", 357 | " def __init__(self, brand, model, type, motor, height, long, wieght):\n", 358 | " super().__init__(brand, model, type)\n", 359 | " self.motor = motor\n", 360 | " self.height = height\n", 361 | " self.long = long\n", 362 | " self.wieght = wieght\n", 363 | "\n", 364 | " def more_info(self):\n", 365 | " print(f\"brand: {self.brand}\\n\"\n", 366 | " f\"model: {self.model}\\n\"\n", 367 | " f\"type: {self.type}\\n\"\n", 368 | " f\"motor: {self.motor}\\n\"\n", 369 | " f\"height: {self.height}\\n\"\n", 370 | " f\"long: {self.long}\\n\"\n", 371 | " f\"wieght: {self.wieght}\")\n", 372 | "\n", 373 | "\n", 374 | "truck = Truck(\"MAN\", \"Isuzi\", \"Katta\", \"23400\", \"23 m\", \"6 m\", '12 t')\n", 375 | "truck.more_info()" 376 | ], 377 | "metadata": { 378 | "collapsed": false, 379 | "pycharm": { 380 | "name": "#%%\n" 381 | } 382 | } 383 | }, 384 | { 385 | "cell_type": "markdown", 386 | "source": [ 387 | "# 3.1\n", 388 | "# \"University\" - parent klass. Konstruktorida esa (university) parametrlari bor.\n", 389 | "# info() - (university) ni print qilib beradi.\n", 390 | "#\n", 391 | "# \"Staff\" - child klass. Unda konstruktirida qo'shimcha (first_name, last_name, age) parametrlari bor.\n", 392 | "# staff_info() - (university, first_name, last_name, age) ni print qilib beradi.\n", 393 | "#\n", 394 | "# \"Student\" - child klass. U \"Staff\" dan vorislik oladi. Unda konstruktirida qo'shimcha (group) parametrlari bor.\n", 395 | "# more_info() - (university, first_name, last_name, age, group) ni print qilib beradi.\n", 396 | "#\n", 397 | "# \"Teacher\" - child klass. U \"Staff\" dan vorislik oladi. Unda konstruktirida qo'shimcha (position, subject) parametrlari bor.\n", 398 | "# more_info() - (university, first_name, last_name, position, subject) ni print qilib beradi.\n", 399 | "#\n", 400 | "# \"OtherStaff\" - child klass. U \"Staff\" dan vorislik oladi. Unda konstruktirida qo'shimcha (position) parametrlari bor.\n", 401 | "# more_info() - (university, first_name, last_name, position,) ni print qilib beradi." 402 | ], 403 | "metadata": { 404 | "collapsed": false, 405 | "pycharm": { 406 | "name": "#%% md\n" 407 | } 408 | } 409 | }, 410 | { 411 | "cell_type": "code", 412 | "execution_count": 12, 413 | "outputs": [ 414 | { 415 | "name": "stdout", 416 | "output_type": "stream", 417 | "text": [ 418 | "University: TUIT\n" 419 | ] 420 | } 421 | ], 422 | "source": [ 423 | "class University:\n", 424 | " def __init__(self, university: str):\n", 425 | " self.university = university\n", 426 | "\n", 427 | " def info(self):\n", 428 | " print(f\"University: {self.university}\")\n", 429 | "\n", 430 | "\n", 431 | "myunver = University(\"TUIT\")\n", 432 | "myunver.info()" 433 | ], 434 | "metadata": { 435 | "collapsed": false, 436 | "pycharm": { 437 | "name": "#%%\n" 438 | } 439 | } 440 | }, 441 | { 442 | "cell_type": "code", 443 | "execution_count": 19, 444 | "outputs": [ 445 | { 446 | "name": "stdout", 447 | "output_type": "stream", 448 | "text": [ 449 | "University: TUIT\n", 450 | "First name: Alisher\n", 451 | "Last name: Usmonov\n", 452 | "Age: 34\n", 453 | "\n" 454 | ] 455 | } 456 | ], 457 | "source": [ 458 | "class Staff(University):\n", 459 | " def __init__(self, university: str, first_name: str, last_name: str, age: int):\n", 460 | " super().__init__(university)\n", 461 | " self.first_name = first_name\n", 462 | " self.last_name = last_name\n", 463 | " self.age = age\n", 464 | "\n", 465 | " def staff_info(self):\n", 466 | " print(f\"University: {self.university}\\n\"\n", 467 | " f\"First name: {self.first_name}\\n\"\n", 468 | " f\"Last name: {self.last_name}\\n\"\n", 469 | " f\"Age: {self.age}\\n\")\n", 470 | "\n", 471 | "\n", 472 | "staff = Staff(\"TUIT\", \"Alisher\", \"Usmonov\", 34)\n", 473 | "staff.staff_info()" 474 | ], 475 | "metadata": { 476 | "collapsed": false, 477 | "pycharm": { 478 | "name": "#%%\n" 479 | } 480 | } 481 | }, 482 | { 483 | "cell_type": "code", 484 | "execution_count": 20, 485 | "outputs": [ 486 | { 487 | "name": "stdout", 488 | "output_type": "stream", 489 | "text": [ 490 | "University: TUIT\n", 491 | "First name: Umidbek\n", 492 | "Last name: Maxammadsoliyev\n", 493 | "Age: 19\n", 494 | "\n", 495 | "University: TUIT\n", 496 | "First name: Umidbek\n", 497 | "Last name: Maxammadsoliyev\n", 498 | "Age: 19\n", 499 | "Group: 210-20\n" 500 | ] 501 | } 502 | ], 503 | "source": [ 504 | "class Student(Staff):\n", 505 | " def __init__(self, university: str, first_name: str, last_name: str, age: int, group: str):\n", 506 | " super().__init__(university, first_name, last_name, age)\n", 507 | " self.group = group\n", 508 | "\n", 509 | " def more_info(self):\n", 510 | " print(f\"University: {self.university}\\n\"\n", 511 | " f\"First name: {self.first_name}\\n\"\n", 512 | " f\"Last name: {self.last_name}\\n\"\n", 513 | " f\"Age: {self.age}\\n\"\n", 514 | " f\"Group: {self.group}\")\n", 515 | "\n", 516 | "\n", 517 | "talaba = Student(\"TUIT\", \"Umidbek\", \"Maxammadsoliyev\", 19, '210-20')\n", 518 | "talaba.staff_info()\n", 519 | "\n", 520 | "talaba.more_info()" 521 | ], 522 | "metadata": { 523 | "collapsed": false, 524 | "pycharm": { 525 | "name": "#%%\n" 526 | } 527 | } 528 | }, 529 | { 530 | "cell_type": "code", 531 | "execution_count": 23, 532 | "outputs": [ 533 | { 534 | "name": "stdout", 535 | "output_type": "stream", 536 | "text": [ 537 | "University: Astrum\n", 538 | "First name: Abdulhodiy\n", 539 | "Last name: Rahmonov\n", 540 | "Position: Teacher\n", 541 | "Suject: English\n" 542 | ] 543 | } 544 | ], 545 | "source": [ 546 | "class Teacher(Staff):\n", 547 | " def __init__(self, university: str, first_name: str, last_name: str, age: int, position: str, subject: str):\n", 548 | " super().__init__(university, first_name, last_name, age)\n", 549 | " self.position = position\n", 550 | " self.subject = subject\n", 551 | "\n", 552 | " def more_info(self):\n", 553 | " print(f\"University: {self.university}\\n\"\n", 554 | " f\"First name: {self.first_name}\\n\"\n", 555 | " f\"Last name: {self.last_name}\\n\"\n", 556 | " f\"Position: {self.position}\\n\"\n", 557 | " f\"Suject: {self.subject}\")\n", 558 | "\n", 559 | "\n", 560 | "teacher = Teacher(\"Astrum\", \"Abdulhodiy\", 'Rahmonov', 24, \"Teacher\", \"English\")\n", 561 | "teacher.more_info()\n" 562 | ], 563 | "metadata": { 564 | "collapsed": false, 565 | "pycharm": { 566 | "name": "#%%\n" 567 | } 568 | } 569 | }, 570 | { 571 | "cell_type": "code", 572 | "execution_count": 26, 573 | "outputs": [ 574 | { 575 | "name": "stdout", 576 | "output_type": "stream", 577 | "text": [ 578 | "University: TUIT\n", 579 | "First name: Ali\n", 580 | "Last name: Vali\n", 581 | "Position: Yugurdak\n", 582 | "\n" 583 | ] 584 | } 585 | ], 586 | "source": [ 587 | "class OtherStaff(Staff):\n", 588 | " def __init__(self, university: str, first_name: str, last_name: str, age: int, position: str):\n", 589 | " super().__init__(university, first_name, last_name, age)\n", 590 | " self.position = position\n", 591 | "\n", 592 | " def more_info(self):\n", 593 | " print(f\"University: {self.university}\\n\"\n", 594 | " f\"First name: {self.first_name}\\n\"\n", 595 | " f\"Last name: {self.last_name}\\n\"\n", 596 | " f\"Position: {self.position}\\n\")\n", 597 | "\n", 598 | "\n", 599 | "other = OtherStaff(\"TUIT\", \"Ali\", \"Vali\", 12, \"Yugurdak\")\n", 600 | "\n", 601 | "other.more_info()" 602 | ], 603 | "metadata": { 604 | "collapsed": false, 605 | "pycharm": { 606 | "name": "#%%\n" 607 | } 608 | } 609 | }, 610 | { 611 | "cell_type": "markdown", 612 | "source": [ 613 | "### 3.2\n", 614 | "### \"Object\" - child klass. U \"University\" dan vorislik oladi. Unda konstruktirida qo'shimcha (name) parametrlari bor.\n", 615 | "### object_info() - (university, name) ni print qilib beradi.\n", 616 | "###\n", 617 | "### \"Computer\" - child klass. U \"Object\" dan vorislik oladi. Unda konstruktirida qo'shimcha (soni, tizimi, holati) parametrlari bor.\n", 618 | "### object_more_info() - (university, name, soni, tizimi, holati) ni print qilib beradi.\n", 619 | "###\n", 620 | "### \"Mebel\" - child klass. U \"Object\" dan vorislik oladi. Unda konstruktirida qo'shimcha (soni, turi, holati) parametrlari bor.\n", 621 | "### object_more_info() - (university, name, soni, turi, holati) ni print qilib beradi." 622 | ], 623 | "metadata": { 624 | "collapsed": false, 625 | "pycharm": { 626 | "name": "#%% md\n" 627 | } 628 | } 629 | }, 630 | { 631 | "cell_type": "code", 632 | "execution_count": 29, 633 | "outputs": [ 634 | { 635 | "name": "stdout", 636 | "output_type": "stream", 637 | "text": [ 638 | "University: TUIT\n", 639 | "Name: Maktab\n", 640 | "\n" 641 | ] 642 | } 643 | ], 644 | "source": [ 645 | "class Object(University):\n", 646 | " def __init__(self, university: str, name: str):\n", 647 | " super().__init__(university)\n", 648 | " self.name = name\n", 649 | "\n", 650 | " def object_info(self):\n", 651 | " print(f\"University: {self.university}\\n\"\n", 652 | " f\"Name: {self.name}\\n\")\n", 653 | "\n", 654 | "\n", 655 | "object = Object(\"TUIT\", \"Maktab\")\n", 656 | "object.object_info()" 657 | ], 658 | "metadata": { 659 | "collapsed": false, 660 | "pycharm": { 661 | "name": "#%%\n" 662 | } 663 | } 664 | }, 665 | { 666 | "cell_type": "code", 667 | "execution_count": 30, 668 | "outputs": [ 669 | { 670 | "name": "stdout", 671 | "output_type": "stream", 672 | "text": [ 673 | "University: TUIT\n", 674 | "Name: HP\n", 675 | "Soni: 23\n", 676 | "Tizimi: Windows\n", 677 | "Holati: A'lo\n", 678 | "\n" 679 | ] 680 | } 681 | ], 682 | "source": [ 683 | "class Computer(Object):\n", 684 | " def __init__(self, university: str, name: str, soni: int, tizimi: str, holati: str):\n", 685 | " super().__init__(university, name)\n", 686 | " self.soni = soni\n", 687 | " self.tizimi = tizimi\n", 688 | " self.holati = holati\n", 689 | "\n", 690 | " def object_more_info(self):\n", 691 | " print(f\"University: {self.university}\\n\"\n", 692 | " f\"Name: {self.name}\\n\"\n", 693 | " f\"Soni: {self.soni}\\n\"\n", 694 | " f\"Tizimi: {self.tizimi}\\n\"\n", 695 | " f\"Holati: {self.holati}\\n\")\n", 696 | "\n", 697 | "\n", 698 | "pc = Computer(\"TUIT\", \"HP\", 23, \"Windows\", \"A'lo\")\n", 699 | "pc.object_more_info()" 700 | ], 701 | "metadata": { 702 | "collapsed": false, 703 | "pycharm": { 704 | "name": "#%%\n" 705 | } 706 | } 707 | }, 708 | { 709 | "cell_type": "code", 710 | "execution_count": 32, 711 | "outputs": [ 712 | { 713 | "name": "stdout", 714 | "output_type": "stream", 715 | "text": [ 716 | "University: TUIT\n", 717 | "Name: Stul\n", 718 | "Soni: 23\n", 719 | "Turi: oddiy\n", 720 | "Holati: yaxshi\n", 721 | "\n" 722 | ] 723 | } 724 | ], 725 | "source": [ 726 | "class Mebel(Object):\n", 727 | " def __init__(self, university: str, name: str, soni: int, turi: str, holati: str):\n", 728 | " super().__init__(university, name)\n", 729 | " self.soni = soni\n", 730 | " self.turi = turi\n", 731 | " self.holati = holati\n", 732 | "\n", 733 | " def object_more_info(self):\n", 734 | " print(f\"University: {self.university}\\n\"\n", 735 | " f\"Name: {self.name}\\n\"\n", 736 | " f\"Soni: {self.soni}\\n\"\n", 737 | " f\"Turi: {self.turi}\\n\"\n", 738 | " f\"Holati: {self.holati}\\n\")\n", 739 | "\n", 740 | "mebel = Mebel(\"TUIT\", \"Stul\", 23, \"oddiy\", \"yaxshi\")\n", 741 | "mebel.object_more_info()" 742 | ], 743 | "metadata": { 744 | "collapsed": false, 745 | "pycharm": { 746 | "name": "#%%\n" 747 | } 748 | } 749 | } 750 | ], 751 | "metadata": { 752 | "kernelspec": { 753 | "display_name": "Python 3", 754 | "language": "python", 755 | "name": "python3" 756 | }, 757 | "language_info": { 758 | "codemirror_mode": { 759 | "name": "ipython", 760 | "version": 2 761 | }, 762 | "file_extension": ".py", 763 | "mimetype": "text/x-python", 764 | "name": "python", 765 | "nbconvert_exporter": "python", 766 | "pygments_lexer": "ipython2", 767 | "version": "2.7.6" 768 | } 769 | }, 770 | "nbformat": 4, 771 | "nbformat_minor": 0 772 | } -------------------------------------------------------------------------------- /python/15-api-result.json: -------------------------------------------------------------------------------- 1 | {"batchcomplete":"","query":{"pages":{"13801":{"pageid":13801,"ns":0,"title":"Python","extract":"Python ([\u02c8p\u028c\u026a\u03b8(\u0259)n] - payton, piton) \u2014 bu turli sohalar uchun yuqori darajadagi umumiy maqsadli dasturlash tili hisoblanadi. Uning dizayn falsafasi muhim chekinishdan foydalangan holda kodning o\u02bbqilishiga urg\u02bbu beradi. Uning til konstruksiyalari va obyektga yo\u02bbnaltirilgan yondashuvi dasturchilarga kichik va yirik loyihalar uchun aniq, mantiqiy kod yozishda yordam berishga qaratilgan. Shuningdek Python sun\u02bciy intellekt hamda ma\u02bclumotlar muhandisiligi sohalarining tili hisoblanadi.\nPython deyarli barcha platformalarda ishlay oladi, xususan Windows, Linux, Mac OS X, Palm OS, Mac OS va boshqalar shular jumlasidandir. Python Microsoft.NET platformasi uchun yozilgan realizatsiyasi ham mavjud bo\u02bblib, uning nomi \u2014 IronPython dasturlash muhitidir.\nGuido van Rossum 1980-yillarning oxirida ABC dasturlash tilining davomchisi sifatida Python ustida ishlay boshladi va birinchi marta 1991-yilda Python 0.9.0 versiyasini ommaga e\u02bclon qildi.\nPython dasturlash tiliga bo\u02bblgan talab yildan yilga oshib bormoqda. CodingDojo portalining tadqiqotlariga ko\u02bbra, 2020-2021-yillarda aynan Python tilida dasturlovchi mutaxassislarga eng ko\u02bbp talab bo\u02bblgan."}}}} -------------------------------------------------------------------------------- /python/15-dars-json.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "collapsed": true, 7 | "pycharm": { 8 | "name": "#%% md\n" 9 | } 10 | }, 11 | "source": [ 12 | "### Ushbu o'zgaruvchini JSON ko'rinishida saqlang va JSON matnini konsolga chiqaring:\n", 13 | "### data = {\"Model\" : \"Malibu\", \"Rang\" : \"Qora\", \"Yil\":2020, \"Narh\":40000}" 14 | ] 15 | }, 16 | { 17 | "cell_type": "code", 18 | "execution_count": 35, 19 | "outputs": [ 20 | { 21 | "name": "stdout", 22 | "output_type": "stream", 23 | "text": [ 24 | "('{\\n'\n", 25 | " ' \"Model\": \"Malibu\",\\n'\n", 26 | " ' \"Rang\": \"Qora\",\\n'\n", 27 | " ' \"Yil\": 2020,\\n'\n", 28 | " ' \"Narh\": 40000\\n'\n", 29 | " '}')\n", 30 | "\n" 31 | ] 32 | } 33 | ], 34 | "source": [ 35 | "import json\n", 36 | "data = {\"Model\": \"Malibu\", \"Rang\":\"Qora\", \"Yil\":2020, \"Narh\":40000}\n", 37 | "json_data = json.dumps(data, indent=4)\n", 38 | "print(json_data)\n", 39 | "print(type(json_data))" 40 | ], 41 | "metadata": { 42 | "collapsed": false, 43 | "pycharm": { 44 | "name": "#%%\n" 45 | } 46 | } 47 | }, 48 | { 49 | "cell_type": "markdown", 50 | "source": [ 51 | "### Ushbu JSON matnni ko'chirib oling, va talabaning ismi va familiyasini konsolga chiqaring:\n", 52 | "### talaba_json = \"\"\"{\"ism\":\"Hasan\",\"familiya\":\"Husanov\",\"tyil\":2000}\"\"\"" 53 | ], 54 | "metadata": { 55 | "collapsed": false, 56 | "pycharm": { 57 | "name": "#%% md\n" 58 | } 59 | } 60 | }, 61 | { 62 | "cell_type": "code", 63 | "execution_count": 6, 64 | "outputs": [ 65 | { 66 | "name": "stdout", 67 | "output_type": "stream", 68 | "text": [ 69 | "ism: Hasan\n", 70 | "familiya:Husanov\n" 71 | ] 72 | } 73 | ], 74 | "source": [ 75 | "import json\n", 76 | "\n", 77 | "talaba_json = \"\"\"{\"ism\":\"Hasan\",\"familiya\":\"Husanov\",\"tyil\":2000}\"\"\"\n", 78 | "\n", 79 | "talaba = json.loads(talaba_json)\n", 80 | "print(f\"ism: {talaba['ism']}\\nfamiliya:{talaba['familiya']}\")" 81 | ], 82 | "metadata": { 83 | "collapsed": false, 84 | "pycharm": { 85 | "name": "#%%\n" 86 | } 87 | } 88 | }, 89 | { 90 | "cell_type": "markdown", 91 | "source": [ 92 | "### Yuqoridagi ikki o'zgaruvchini alohida JSON fayllarga saqlang." 93 | ], 94 | "metadata": { 95 | "collapsed": false, 96 | "pycharm": { 97 | "name": "#%% md\n" 98 | } 99 | } 100 | }, 101 | { 102 | "cell_type": "code", 103 | "execution_count": 8, 104 | "outputs": [], 105 | "source": [ 106 | "import json\n", 107 | "with open(\"15-json1.json\", \"w\") as f1:\n", 108 | " json.dump(data, f1)\n", 109 | "\n", 110 | "\n", 111 | "with open(\"15-json2.json\", \"w\") as f2:\n", 112 | " json.dump(talaba, f2)" 113 | ], 114 | "metadata": { 115 | "collapsed": false, 116 | "pycharm": { 117 | "name": "#%%\n" 118 | } 119 | } 120 | }, 121 | { 122 | "cell_type": "markdown", 123 | "source": [ 124 | "### Quyidagi JSON faylni yuklab oling. Faylda 3 ta talabaning ism va familiyasi saqlangan.\n", 125 | "### Ularning har birini alohida qatordan \"Ism Familiya, n-kurs, Fakultet talabasi\" ko'rinishida konsolga chiqaring." 126 | ], 127 | "metadata": { 128 | "collapsed": false, 129 | "pycharm": { 130 | "name": "#%% md\n" 131 | } 132 | } 133 | }, 134 | { 135 | "cell_type": "code", 136 | "execution_count": 16, 137 | "outputs": [ 138 | { 139 | "name": "stdout", 140 | "output_type": "stream", 141 | "text": [ 142 | "Tom Price, 4 - kurs, Engineering talabasi\n", 143 | "Nick Thameson, 3 - kurs, Computer Science talabasi\n", 144 | "John Doe, 2 - kurs, ICT talabasi\n" 145 | ] 146 | } 147 | ], 148 | "source": [ 149 | "import json\n", 150 | "\n", 151 | "with open(\"15-students.json\", 'r') as f:\n", 152 | " students = json.load(f)\n", 153 | "for student in students['student']:\n", 154 | " print(f\"{student['name']} {student['lastname']}, {student['year']} - kurs, {student['faculty']} talabasi\")" 155 | ], 156 | "metadata": { 157 | "collapsed": false, 158 | "pycharm": { 159 | "name": "#%%\n" 160 | } 161 | } 162 | }, 163 | { 164 | "cell_type": "markdown", 165 | "source": [ 166 | "### Quyidagi bog'lamaga kirsangiz, Wikipediadagi Python dasturlash tili haqidagi maqolani JSON ko'rinishida ko'rishingiz mumkin.\n", 167 | "### Brauzerda chiqqan ma'lumotni JSON ko'rinishida saqlang (brauzerda Ctrl+S tugmasini bosib).\n", 168 | "### Faylni Pythonda oching va konsolga maqolaning sarlavhasi (title) va qisqa matnini (extract) chiqaring:\n", 169 | "### https://uz.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro&explaintext&redirects=1&titles=Python" 170 | ], 171 | "metadata": { 172 | "collapsed": false, 173 | "pycharm": { 174 | "name": "#%% md\n" 175 | } 176 | } 177 | }, 178 | { 179 | "cell_type": "code", 180 | "execution_count": 34, 181 | "outputs": [ 182 | { 183 | "name": "stdout", 184 | "output_type": "stream", 185 | "text": [ 186 | "'Python'\n", 187 | "('Python ([ˈpʌɪθ(ə)n] - payton, piton) — bu turli sohalar uchun yuqori '\n", 188 | " 'darajadagi umumiy maqsadli dasturlash tili hisoblanadi. Uning dizayn '\n", 189 | " 'falsafasi muhim chekinishdan foydalangan holda kodning oʻqilishiga urgʻu '\n", 190 | " 'beradi. Uning til konstruksiyalari va obyektga yoʻnaltirilgan yondashuvi '\n", 191 | " 'dasturchilarga kichik va yirik loyihalar uchun aniq, mantiqiy kod yozishda '\n", 192 | " 'yordam berishga qaratilgan. Shuningdek Python sunʼiy intellekt hamda '\n", 193 | " 'maʼlumotlar muhandisiligi sohalarining tili hisoblanadi.\\n'\n", 194 | " 'Python deyarli barcha platformalarda ishlay oladi, xususan Windows, Linux, '\n", 195 | " 'Mac OS X, Palm OS, Mac OS va boshqalar shular jumlasidandir. Python '\n", 196 | " 'Microsoft.NET platformasi uchun yozilgan realizatsiyasi ham mavjud boʻlib, '\n", 197 | " 'uning nomi — IronPython dasturlash muhitidir.\\n'\n", 198 | " 'Guido van Rossum 1980-yillarning oxirida ABC dasturlash tilining davomchisi '\n", 199 | " 'sifatida Python ustida ishlay boshladi va birinchi marta 1991-yilda Python '\n", 200 | " '0.9.0 versiyasini ommaga eʼlon qildi.\\n'\n", 201 | " 'Python dasturlash tiliga boʻlgan talab yildan yilga oshib bormoqda. '\n", 202 | " 'CodingDojo portalining tadqiqotlariga koʻra, 2020-2021-yillarda aynan Python '\n", 203 | " 'tilida dasturlovchi mutaxassislarga eng koʻp talab boʻlgan.')\n" 204 | ] 205 | } 206 | ], 207 | "source": [ 208 | "import json\n", 209 | "# from pprint import pprint as print\n", 210 | "\n", 211 | "with open(\"15-api-result.json\", 'r') as f:\n", 212 | " result = json.load(f)\n", 213 | "print(result['query']['pages']['13801']['title'])\n", 214 | "print(result['query']['pages']['13801']['extract'])" 215 | ], 216 | "metadata": { 217 | "collapsed": false, 218 | "pycharm": { 219 | "name": "#%%\n" 220 | } 221 | } 222 | }, 223 | { 224 | "cell_type": "code", 225 | "execution_count": null, 226 | "outputs": [], 227 | "source": [], 228 | "metadata": { 229 | "collapsed": false, 230 | "pycharm": { 231 | "name": "#%%\n" 232 | } 233 | } 234 | } 235 | ], 236 | "metadata": { 237 | "kernelspec": { 238 | "display_name": "Python 3", 239 | "language": "python", 240 | "name": "python3" 241 | }, 242 | "language_info": { 243 | "codemirror_mode": { 244 | "name": "ipython", 245 | "version": 2 246 | }, 247 | "file_extension": ".py", 248 | "mimetype": "text/x-python", 249 | "name": "python", 250 | "nbconvert_exporter": "python", 251 | "pygments_lexer": "ipython2", 252 | "version": "2.7.6" 253 | } 254 | }, 255 | "nbformat": 4, 256 | "nbformat_minor": 0 257 | } -------------------------------------------------------------------------------- /python/15-json1.json: -------------------------------------------------------------------------------- 1 | {"Model": "Malibu", "Rang": "Qora", "Yil": 2020, "Narh": 40000} -------------------------------------------------------------------------------- /python/15-json2.json: -------------------------------------------------------------------------------- 1 | {"ism": "Hasan", "familiya": "Husanov", "tyil": 2000} -------------------------------------------------------------------------------- /python/15-students.json: -------------------------------------------------------------------------------- 1 | {"student": [{"id": "01", "name": "Tom", "lastname": "Price", "year": 4, "faculty": "Engineering"}, {"id": "02", "name": "Nick", "lastname": "Thameson", "year": 3, "faculty": "Computer Science"}, {"id": "03", "name": "John", "lastname": "Doe", "year": 2, "faculty": "ICT"}]} -------------------------------------------------------------------------------- /python/16-dars-loyiha-test-dasturi.py: -------------------------------------------------------------------------------- 1 | import json 2 | # from pprint import pprint as print 3 | from tabulate import tabulate 4 | 5 | with open('16-tests.json', 'r') as f1: 6 | testjs = json.load(f1) 7 | 8 | with open('16-users.json', 'r') as f2: 9 | usersjs = json.load(f2) 10 | 11 | keys = ['a', "b", "c", "d"] 12 | 13 | 14 | def printTable(users): 15 | data = [user.values() for user in users] 16 | print(tabulate(data, headers=['Name', 'Played', "Best score"], tablefmt='orgtbl')) 17 | 18 | 19 | printTable(usersjs) 20 | -------------------------------------------------------------------------------- /python/16-tests.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "question": "Python dasturlash tilining asoschisi kim?", 4 | "answers": [ 5 | { 6 | "key": "Guido van Rossum", 7 | "isTrue": true 8 | }, 9 | { 10 | "key": "Monty Python", 11 | "isTrue": false 12 | }, 13 | { 14 | "key": "Stefen Houking", 15 | "isTrue": false 16 | }, 17 | { 18 | "key": "Pavel Durov", 19 | "isTrue": false 20 | } 21 | ] 22 | }, 23 | { 24 | "question": "Quyidagilar qanday nomlanadi:\n\n\t+, 0, 'Integer'", 25 | "answers": [ 26 | { 27 | "key": "Integer, operator, string", 28 | "isTrue": false 29 | }, 30 | { 31 | "key": "String, operator, integer", 32 | "isTrue": false 33 | }, 34 | { 35 | "key": "Operator, string, integer", 36 | "isTrue": false 37 | }, 38 | { 39 | "key": "Operator, integer, string", 40 | "isTrue": true 41 | } 42 | ] 43 | }, 44 | { 45 | "question": "input() funksiyasi qanday turdagi qiymat qaytaradi?", 46 | "answers": [ 47 | { 48 | "key": "List", 49 | "isTrue": false 50 | }, 51 | { 52 | "key": "String", 53 | "isTrue": true 54 | }, 55 | { 56 | "key": "Integer", 57 | "isTrue": false 58 | }, 59 | { 60 | "key": "Qiymat qaytarmaydi", 61 | "isTrue": false 62 | } 63 | ] 64 | }, 65 | { 66 | "question": "Quyidagi \"figurali qavslar\" orqali qanday turdagi ma'lumotlar hosil qilish mumkin:\n\n\t{}", 67 | "answers": [ 68 | { 69 | "key": "Set", 70 | "isTrue": false 71 | }, 72 | { 73 | "key": "Dict", 74 | "isTrue": false 75 | }, 76 | { 77 | "key": "List", 78 | "isTrue": false 79 | }, 80 | { 81 | "key": "Set yoki dict", 82 | "isTrue": true 83 | } 84 | ] 85 | }, 86 | { 87 | "question": "for bu ...", 88 | "answers": [ 89 | { 90 | "key": "Qiymat qaytaruvchi funksiya", 91 | "isTrue": false 92 | }, 93 | { 94 | "key": "Sikl", 95 | "isTrue": true 96 | }, 97 | { 98 | "key": "Qiymat qaytarmaydigan funksiya", 99 | "isTrue": false 100 | }, 101 | { 102 | "key": "Operator", 103 | "isTrue": false 104 | } 105 | ] 106 | }, 107 | { 108 | "question": "Quyidagi kod qanday natija qaytaradi?\n\n\ta = 5\n\tb = 2\n\tc = a % b\n\tprint(c)", 109 | "answers": [ 110 | { 111 | "key": "1", 112 | "isTrue": true 113 | }, 114 | { 115 | "key": "2", 116 | "isTrue": false 117 | }, 118 | { 119 | "key": "10", 120 | "isTrue": false 121 | }, 122 | { 123 | "key": "25", 124 | "isTrue": false 125 | } 126 | ] 127 | }, 128 | { 129 | "question": "Quyidagi kod qanday natija qaytaradi?\n\n\ta = ['12', '21']\n\tb = '11' + a[1]\n\tprint(b)", 130 | "answers": [ 131 | { 132 | "key": "1112", 133 | "isTrue": false 134 | }, 135 | { 136 | "key": "23", 137 | "isTrue": false 138 | }, 139 | { 140 | "key": "1121", 141 | "isTrue": true 142 | }, 143 | { 144 | "key": "32", 145 | "isTrue": false 146 | } 147 | ] 148 | }, 149 | { 150 | "question": "Quyidagi kod qanday natija qaytaradi?\n\n\ta, b = 1, 2\n\tb = a\n\tx, y = b, a\n\tc = str(x) * y\n\tprint(c)", 151 | "answers": [ 152 | { 153 | "key": "1", 154 | "isTrue": true 155 | }, 156 | { 157 | "key": "2", 158 | "isTrue": false 159 | }, 160 | { 161 | "key": "11", 162 | "isTrue": false 163 | }, 164 | { 165 | "key": "21", 166 | "isTrue": false 167 | } 168 | ] 169 | }, 170 | { 171 | "question": "Quyidagi kod qanday natija qaytaradi?\n\n\ta = 2\n\tb = -2\n\twhile a >= 0:\n\t\tb = b ** a\n\t\ta -= 1\n\tprint(b)", 172 | "answers": [ 173 | { 174 | "key": "4", 175 | "isTrue": false 176 | }, 177 | { 178 | "key": "-4", 179 | "isTrue": false 180 | }, 181 | { 182 | "key": "-5", 183 | "isTrue": false 184 | }, 185 | { 186 | "key": "1", 187 | "isTrue": true 188 | } 189 | ] 190 | }, 191 | { 192 | "question": "Quyidagi kod qanday natija qaytaradi?\n\n\tprint(4 + 5 = 9)", 193 | "answers": [ 194 | { 195 | "key": "Kod xato", 196 | "isTrue": true 197 | }, 198 | { 199 | "key": "1", 200 | "isTrue": false 201 | }, 202 | { 203 | "key": "True", 204 | "isTrue": false 205 | }, 206 | { 207 | "key": "18", 208 | "isTrue": false 209 | } 210 | ] 211 | } 212 | ] -------------------------------------------------------------------------------- /python/16-users.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "Nodir", 4 | "played": 5, 5 | "best_score": 2 6 | }, 7 | { 8 | "name": "Akmal", 9 | "played": 4, 10 | "best_score": 4 11 | }, 12 | { 13 | "name": "Komiljon", 14 | "played": 2, 15 | "best_score": 6 16 | }, 17 | { 18 | "name": "John", 19 | "played": 1, 20 | "best_score": 7 21 | }, 22 | { 23 | "name": "Umidbek", 24 | "played": 1, 25 | "best_score": 2 26 | } 27 | ] -------------------------------------------------------------------------------- /python/6-dars-for-loop-1.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "c4419105-4edd-4a61-ad8a-e49c89129b3a", 6 | "metadata": {}, 7 | "source": [ 8 | "### 1. K va N soni berilgan (N > 0). K sonini N marta print qiling." 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 4, 14 | "id": "4efb7fcf-8b5b-4ed0-bf82-6db50893d480", 15 | "metadata": {}, 16 | "outputs": [ 17 | { 18 | "name": "stdin", 19 | "output_type": "stream", 20 | "text": [ 21 | "K = 2345\n", 22 | "N = 5\n" 23 | ] 24 | }, 25 | { 26 | "name": "stdout", 27 | "output_type": "stream", 28 | "text": [ 29 | "2345\n", 30 | "2345\n", 31 | "2345\n", 32 | "2345\n", 33 | "2345\n" 34 | ] 35 | } 36 | ], 37 | "source": [ 38 | "k = int(input(\"K = \"))\n", 39 | "n = int(input(\"N = \"))\n", 40 | "\n", 41 | "for _ in range(n):\n", 42 | " print(k)" 43 | ] 44 | }, 45 | { 46 | "cell_type": "markdown", 47 | "id": "920adf32-12cf-4949-a3cc-de7ed7d9cdf7", 48 | "metadata": {}, 49 | "source": [ 50 | "### 2. 1 dan n gacha bo'lgan toq sonlar yig'indisini toping." 51 | ] 52 | }, 53 | { 54 | "cell_type": "code", 55 | "execution_count": 6, 56 | "id": "86bbbd0b-884c-4678-9386-41bf35a5058a", 57 | "metadata": {}, 58 | "outputs": [ 59 | { 60 | "name": "stdin", 61 | "output_type": "stream", 62 | "text": [ 63 | "N = 5\n" 64 | ] 65 | }, 66 | { 67 | "name": "stdout", 68 | "output_type": "stream", 69 | "text": [ 70 | "9\n" 71 | ] 72 | } 73 | ], 74 | "source": [ 75 | "n = int(input(\"N = \"))\n", 76 | "\n", 77 | "sum_toq = 0\n", 78 | "for i in range(1, n+1):\n", 79 | " if i % 2 == 1:\n", 80 | " sum_toq += i\n", 81 | "print(sum_toq)" 82 | ] 83 | }, 84 | { 85 | "cell_type": "markdown", 86 | "id": "779b8ada-6ef6-4026-b324-4b91a7580374", 87 | "metadata": {}, 88 | "source": [ 89 | "### 3. 1 dan n gacha bo'lgan 3 ga bo'linadigan lekin 9 ga bo'linmidigan sonlar yig'indisini toping." 90 | ] 91 | }, 92 | { 93 | "cell_type": "code", 94 | "execution_count": 9, 95 | "id": "b5d7d43a-93b5-4961-8812-52b3a1d0358d", 96 | "metadata": {}, 97 | "outputs": [ 98 | { 99 | "name": "stdin", 100 | "output_type": "stream", 101 | "text": [ 102 | "N = 123\n" 103 | ] 104 | }, 105 | { 106 | "name": "stdout", 107 | "output_type": "stream", 108 | "text": [ 109 | "1641\n" 110 | ] 111 | } 112 | ], 113 | "source": [ 114 | "n = int(input(\"N = \"))\n", 115 | "\n", 116 | "summa = 0\n", 117 | "for i in range(3, n):\n", 118 | " if i % 3 == 0 and i % 9 != 0:\n", 119 | " summa += i\n", 120 | "print(summa)" 121 | ] 122 | }, 123 | { 124 | "cell_type": "markdown", 125 | "id": "27b61e86-2995-4f4f-8e2e-d779efe1b650", 126 | "metadata": {}, 127 | "source": [ 128 | "### 4. 1 dan n gacha bo'lgan sonlarni kvadratlari yig'indisini toping." 129 | ] 130 | }, 131 | { 132 | "cell_type": "code", 133 | "execution_count": 11, 134 | "id": "b3170232-d408-43bf-8b5e-fdb64259dceb", 135 | "metadata": {}, 136 | "outputs": [ 137 | { 138 | "name": "stdin", 139 | "output_type": "stream", 140 | "text": [ 141 | "N = 3\n" 142 | ] 143 | }, 144 | { 145 | "name": "stdout", 146 | "output_type": "stream", 147 | "text": [ 148 | "14\n" 149 | ] 150 | } 151 | ], 152 | "source": [ 153 | "n = int(input(\"N = \"))\n", 154 | "\n", 155 | "summa = 0\n", 156 | "for i in range(n+1):\n", 157 | " summa += i**2\n", 158 | "print(summa)" 159 | ] 160 | }, 161 | { 162 | "cell_type": "markdown", 163 | "id": "02f7383e-15a3-4fdf-9a20-e076fd16d530", 164 | "metadata": {}, 165 | "source": [ 166 | "### 5. Soz kiritaman. Undan keyin 1 dan – sozni uzunligigacha bolgan son kiritishimni sorasin. Kiritilgan sonni tartibidagi harifni soz da olib tashlasin." 167 | ] 168 | }, 169 | { 170 | "cell_type": "code", 171 | "execution_count": 12, 172 | "id": "5405efe9-b31b-481a-b5f8-661e23ad0fd9", 173 | "metadata": {}, 174 | "outputs": [ 175 | { 176 | "ename": "IndentationError", 177 | "evalue": "expected an indented block (764395382.py, line 9)", 178 | "output_type": "error", 179 | "traceback": [ 180 | "\u001b[1;36m Input \u001b[1;32mIn [12]\u001b[1;36m\u001b[0m\n\u001b[1;33m \u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mIndentationError\u001b[0m\u001b[1;31m:\u001b[0m expected an indented block\n" 181 | ] 182 | } 183 | ], 184 | "source": [ 185 | "soz = input(\"So'z kiriting \")\n", 186 | "l = len(soz)\n", 187 | "print(f\"1 dan {l} gacha bo'lgan son kiriting:\")\n", 188 | "son = int(input())\n", 189 | "\n", 190 | "for i in range(l):\n", 191 | " if son == i:\n", 192 | " \n", 193 | "\n" 194 | ] 195 | }, 196 | { 197 | "cell_type": "markdown", 198 | "id": "95ec5e45-3e35-4809-87fa-195b7986cb03", 199 | "metadata": {}, 200 | "source": [ 201 | "### 6. Agar online magazindan kiyim olsangiz va butun narx 100000 dan ko'p bo'lsa sizga 10% skidka qilib bersin . agar 50000 dan ko'p bo'lsa sizga 5% skidka qilib bersin. agar undan kam bo'lsa o'zini narxida bersin." 202 | ] 203 | }, 204 | { 205 | "cell_type": "code", 206 | "execution_count": null, 207 | "id": "5a684249-74bf-44d1-b206-9af24c942ef8", 208 | "metadata": {}, 209 | "outputs": [], 210 | "source": [] 211 | }, 212 | { 213 | "cell_type": "markdown", 214 | "id": "cc78836b-7492-4824-81d7-3f9ef5ac792c", 215 | "metadata": {}, 216 | "source": [ 217 | "### 7. Sonlar berilgan A va B (A < B). A va B oraligida joylashgan sonlarni kamayish tartibida print qilin (A va B) shu oraliqqa kirmasin. Shu sonlarni sonini (uzunligini) print qiling" 218 | ] 219 | }, 220 | { 221 | "cell_type": "code", 222 | "execution_count": 15, 223 | "id": "3cfc8fba-5d8d-4622-b2c0-a0fdc99e32fa", 224 | "metadata": {}, 225 | "outputs": [ 226 | { 227 | "name": "stdin", 228 | "output_type": "stream", 229 | "text": [ 230 | "A = 3\n", 231 | "B = 13\n" 232 | ] 233 | }, 234 | { 235 | "name": "stdout", 236 | "output_type": "stream", 237 | "text": [ 238 | "12\n", 239 | "11\n", 240 | "10\n", 241 | "9\n", 242 | "8\n", 243 | "7\n", 244 | "6\n", 245 | "5\n", 246 | "4\n" 247 | ] 248 | } 249 | ], 250 | "source": [ 251 | "a = int(input(\"A = \"))\n", 252 | "b = int(input(\"B = \"))\n", 253 | "\n", 254 | "for i in range(b-1, a, -1):\n", 255 | " print(i)" 256 | ] 257 | }, 258 | { 259 | "cell_type": "markdown", 260 | "id": "5f02135b-a177-4e10-b1a5-4d99ccd92f3b", 261 | "metadata": {}, 262 | "source": [ 263 | "### 8. Son berilgan – u 1 kg konfetni narxi. 1, 2, ….. , 10 kg uchun narxni print qiling." 264 | ] 265 | }, 266 | { 267 | "cell_type": "code", 268 | "execution_count": 17, 269 | "id": "25092a36-35c3-43cc-a749-792c2c088616", 270 | "metadata": {}, 271 | "outputs": [ 272 | { 273 | "name": "stdin", 274 | "output_type": "stream", 275 | "text": [ 276 | "Konfet narxini kiriting: 13000\n" 277 | ] 278 | }, 279 | { 280 | "name": "stdout", 281 | "output_type": "stream", 282 | "text": [ 283 | "1 kg konfet narxi: 13000\n", 284 | "2 kg konfet narxi: 26000\n", 285 | "3 kg konfet narxi: 39000\n", 286 | "4 kg konfet narxi: 52000\n", 287 | "5 kg konfet narxi: 65000\n", 288 | "6 kg konfet narxi: 78000\n", 289 | "7 kg konfet narxi: 91000\n", 290 | "8 kg konfet narxi: 104000\n", 291 | "9 kg konfet narxi: 117000\n", 292 | "10 kg konfet narxi: 130000\n" 293 | ] 294 | } 295 | ], 296 | "source": [ 297 | "son = int(input(\"Konfet narxini kiriting: \"))\n", 298 | "\n", 299 | "for i in range(1, 11):\n", 300 | " print(f\"{i} kg konfet narxi: {son * i}\")" 301 | ] 302 | }, 303 | { 304 | "cell_type": "markdown", 305 | "id": "4caa5a87-8825-46e1-8238-8b0c7d4f8851", 306 | "metadata": {}, 307 | "source": [ 308 | "### 9. Son berilgan – u 1 kg konfet narxi . 0.1, 0.2, …. , 1 kg uchun narxniprint qiling." 309 | ] 310 | }, 311 | { 312 | "cell_type": "code", 313 | "execution_count": 19, 314 | "id": "8adf14ad-3193-4181-9100-94c8d7895907", 315 | "metadata": {}, 316 | "outputs": [ 317 | { 318 | "name": "stdin", 319 | "output_type": "stream", 320 | "text": [ 321 | "Konfet narxini kiriting: 12000\n" 322 | ] 323 | }, 324 | { 325 | "name": "stdout", 326 | "output_type": "stream", 327 | "text": [ 328 | "0.1 kg konfet narxi: 1200.0\n", 329 | "0.2 kg konfet narxi: 2400.0\n", 330 | "0.3 kg konfet narxi: 3600.0\n", 331 | "0.4 kg konfet narxi: 4800.0\n", 332 | "0.5 kg konfet narxi: 6000.0\n", 333 | "0.6 kg konfet narxi: 7200.0\n", 334 | "0.7 kg konfet narxi: 8400.0\n", 335 | "0.8 kg konfet narxi: 9600.0\n", 336 | "0.9 kg konfet narxi: 10800.0\n", 337 | "1.0 kg konfet narxi: 12000.0\n" 338 | ] 339 | } 340 | ], 341 | "source": [ 342 | "son = int(input(\"Konfet narxini kiriting: \"))\n", 343 | "\n", 344 | "for i in range(1, 11):\n", 345 | " print(f\"{i/10} kg konfet narxi: {son * i/10}\")" 346 | ] 347 | }, 348 | { 349 | "cell_type": "markdown", 350 | "id": "cde21c09-13fe-4163-b0a8-d2074bb57b75", 351 | "metadata": {}, 352 | "source": [ 353 | "### 10. Butun sonlar berilgan A va B (A < B). A va B oralig’idagi butun sonlar kvadratini va ularning yig’indisini print qiling. A va B ham bu oraliqga kirsin. Masalan: 1, 2, 3 -> 1, 4, 9 -> 14" 354 | ] 355 | }, 356 | { 357 | "cell_type": "code", 358 | "execution_count": 3, 359 | "id": "82715437-f90c-4ff0-b4f4-bf28c19e3356", 360 | "metadata": {}, 361 | "outputs": [ 362 | { 363 | "name": "stdin", 364 | "output_type": "stream", 365 | "text": [ 366 | "A = 2\n", 367 | "B = 6\n" 368 | ] 369 | }, 370 | { 371 | "name": "stdout", 372 | "output_type": "stream", 373 | "text": [ 374 | "2 ning kvadrati 4\n", 375 | "3 ning kvadrati 9\n", 376 | "4 ning kvadrati 16\n", 377 | "5 ning kvadrati 25\n", 378 | "54\n" 379 | ] 380 | } 381 | ], 382 | "source": [ 383 | "a = int(input(\"A = \"))\n", 384 | "b = int(input(\"B = \"))\n", 385 | "\n", 386 | "sum = 0\n", 387 | "\n", 388 | "for i in range(a, b):\n", 389 | " print(f\"{i} ning kvadrati {i**2}\")\n", 390 | " sum += i**2\n", 391 | "print(sum)" 392 | ] 393 | }, 394 | { 395 | "cell_type": "markdown", 396 | "id": "c0661680-aef4-4c8b-8658-3b4533cf7320", 397 | "metadata": {}, 398 | "source": [ 399 | "### 11. Butun son berilgan A va N (N >0). Sikldan foydalangan holda A ni 1 – N bolgan darajasini print qililar" 400 | ] 401 | }, 402 | { 403 | "cell_type": "code", 404 | "execution_count": 5, 405 | "id": "ec1ddf72-3065-448d-98dc-a1e253cfe130", 406 | "metadata": {}, 407 | "outputs": [ 408 | { 409 | "name": "stdin", 410 | "output_type": "stream", 411 | "text": [ 412 | "a = 2\n", 413 | "n = 6\n" 414 | ] 415 | }, 416 | { 417 | "name": "stdout", 418 | "output_type": "stream", 419 | "text": [ 420 | "2 ning 1 - darajasi: 2\n", 421 | "2 ning 2 - darajasi: 4\n", 422 | "2 ning 3 - darajasi: 8\n", 423 | "2 ning 4 - darajasi: 16\n", 424 | "2 ning 5 - darajasi: 32\n" 425 | ] 426 | } 427 | ], 428 | "source": [ 429 | "a = int(input('a = '))\n", 430 | "n = int(input('n = '))\n", 431 | " \n", 432 | "for i in range(1, n):\n", 433 | " print(f\"{a} ning {i} - darajasi: {a**i}\")" 434 | ] 435 | }, 436 | { 437 | "cell_type": "markdown", 438 | "id": "b628ee70-193b-4f05-bad1-df73da5b1e87", 439 | "metadata": {}, 440 | "source": [ 441 | "### 12. Butun son berilgan N (N > 0). 1 – N gacha bolgan sonlar kopaytmasini toping." 442 | ] 443 | }, 444 | { 445 | "cell_type": "code", 446 | "execution_count": 6, 447 | "id": "9c25b71b-a26b-434e-a578-e734e9189a7f", 448 | "metadata": {}, 449 | "outputs": [ 450 | { 451 | "name": "stdin", 452 | "output_type": "stream", 453 | "text": [ 454 | "n = 5\n" 455 | ] 456 | }, 457 | { 458 | "name": "stdout", 459 | "output_type": "stream", 460 | "text": [ 461 | "120\n" 462 | ] 463 | } 464 | ], 465 | "source": [ 466 | "n = int(input('n = '))\n", 467 | "\n", 468 | "k = 1\n", 469 | "\n", 470 | "for i in range(1, n+1):\n", 471 | " k *= i\n", 472 | "print(k) " 473 | ] 474 | } 475 | ], 476 | "metadata": { 477 | "kernelspec": { 478 | "display_name": "Python 3 (ipykernel)", 479 | "language": "python", 480 | "name": "python3" 481 | }, 482 | "language_info": { 483 | "codemirror_mode": { 484 | "name": "ipython", 485 | "version": 3 486 | }, 487 | "file_extension": ".py", 488 | "mimetype": "text/x-python", 489 | "name": "python", 490 | "nbconvert_exporter": "python", 491 | "pygments_lexer": "ipython3", 492 | "version": "3.9.7" 493 | } 494 | }, 495 | "nbformat": 4, 496 | "nbformat_minor": 5 497 | } 498 | -------------------------------------------------------------------------------- /python/6-dars-for-loop-2.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "ab0437f0-c28c-4015-8d6d-db3b001bcd78", 6 | "metadata": {}, 7 | "source": [ 8 | "### 1. So’z kiritilgan uni “hello” uni birinchi ikkita harifini yangi o'zgaruvchiga qolgan qismini ikkichi o’zgaruvchiga berib print qiling." 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 7, 14 | "id": "98faffda-d8f7-40ff-ac7b-fab7920442b2", 15 | "metadata": {}, 16 | "outputs": [ 17 | { 18 | "name": "stdin", 19 | "output_type": "stream", 20 | "text": [ 21 | "So'z kiriting: hello\n" 22 | ] 23 | }, 24 | { 25 | "name": "stdout", 26 | "output_type": "stream", 27 | "text": [ 28 | "he llo\n" 29 | ] 30 | } 31 | ], 32 | "source": [ 33 | "soz = input(\"So'z kiriting: \") \n", 34 | "\n", 35 | "var1 = soz[:2]\n", 36 | "var2 = soz[2:]\n", 37 | "\n", 38 | "print(var1, var2)" 39 | ] 40 | }, 41 | { 42 | "cell_type": "markdown", 43 | "id": "1b32d85d-5e74-4c84-96ff-3a4d547365c6", 44 | "metadata": {}, 45 | "source": [ 46 | "### 2. So’z kiritilgan “hello” uni birinchi va oxirgi hariflarini almashtiring “oellh”." 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": 13, 52 | "id": "789b8c7e-821d-4827-bdf9-2d2e73c851d9", 53 | "metadata": {}, 54 | "outputs": [ 55 | { 56 | "name": "stdout", 57 | "output_type": "stream", 58 | "text": [ 59 | "oellh\n" 60 | ] 61 | } 62 | ], 63 | "source": [ 64 | "soz = 'hello'\n", 65 | "\n", 66 | "soz = soz[-1] + soz[1:-1] + soz[0]\n", 67 | "\n", 68 | "print(soz) " 69 | ] 70 | }, 71 | { 72 | "cell_type": "markdown", 73 | "id": "3638251f-98c6-494f-8a6f-962d4ed5ffee", 74 | "metadata": {}, 75 | "source": [ 76 | "### 3. restart so'zini resta$t holatiga keltiring." 77 | ] 78 | }, 79 | { 80 | "cell_type": "code", 81 | "execution_count": 12, 82 | "id": "556aebe2-c2a4-41e9-855d-a9d449ffc6b0", 83 | "metadata": {}, 84 | "outputs": [ 85 | { 86 | "name": "stdout", 87 | "output_type": "stream", 88 | "text": [ 89 | "resta$t\n" 90 | ] 91 | } 92 | ], 93 | "source": [ 94 | "soz = 'restart'\n", 95 | "\n", 96 | "soz = soz[:5] + \"$\" + soz[6:]\n", 97 | " \n", 98 | "print(soz)" 99 | ] 100 | }, 101 | { 102 | "cell_type": "markdown", 103 | "id": "618574fc-ba39-47c3-a447-90c8eae67885", 104 | "metadata": {}, 105 | "source": [ 106 | "### 4. 'abc', 'xyz' ikkita string berilgan uni 'xyc abz' shu holatga keltirish kerak." 107 | ] 108 | }, 109 | { 110 | "cell_type": "code", 111 | "execution_count": 19, 112 | "id": "f473f4db-0ec6-4c6a-a264-720bcddbce6a", 113 | "metadata": {}, 114 | "outputs": [ 115 | { 116 | "name": "stdout", 117 | "output_type": "stream", 118 | "text": [ 119 | "xyc abz\n" 120 | ] 121 | } 122 | ], 123 | "source": [ 124 | "str1 = 'abc'\n", 125 | "str2 = 'xyz'\n", 126 | "\n", 127 | "res = str2[:2] + str1[-1] + ' ' + str1[:2] + str2[-1]\n", 128 | "print(res)" 129 | ] 130 | }, 131 | { 132 | "cell_type": "markdown", 133 | "id": "49012062-54eb-4375-af56-5e9b4699d27f", 134 | "metadata": {}, 135 | "source": [ 136 | "### 5. So’z kiritaman va istalgan son kiritaman shu sondagi indexdagi belgini ochirib sozni chiqarsin." 137 | ] 138 | }, 139 | { 140 | "cell_type": "code", 141 | "execution_count": 22, 142 | "id": "d57bbe35-4e8a-4b4e-ae44-1efb03273a4b", 143 | "metadata": {}, 144 | "outputs": [ 145 | { 146 | "name": "stdin", 147 | "output_type": "stream", 148 | "text": [ 149 | "So'z kiriting: salom\n" 150 | ] 151 | }, 152 | { 153 | "name": "stdout", 154 | "output_type": "stream", 155 | "text": [ 156 | "0-5 oralig'idagi son kiriting: \n" 157 | ] 158 | }, 159 | { 160 | "name": "stdin", 161 | "output_type": "stream", 162 | "text": [ 163 | " 1\n" 164 | ] 165 | }, 166 | { 167 | "name": "stdout", 168 | "output_type": "stream", 169 | "text": [ 170 | "slom\n" 171 | ] 172 | } 173 | ], 174 | "source": [ 175 | "soz = input(\"So'z kiriting: \")\n", 176 | "print(f\"0-{len(soz)} oralig'idagi son kiriting: \")\n", 177 | "son = int(input())\n", 178 | "\n", 179 | "soz = soz[:son] + soz[son+1:]\n", 180 | "print(soz)" 181 | ] 182 | }, 183 | { 184 | "cell_type": "markdown", 185 | "id": "7e2aee86-fab5-47b7-b427-f7efff346eb0", 186 | "metadata": {}, 187 | "source": [ 188 | "### 6. So’z kiritilgan kichik hariflar bilan uni boshi va oxirini katta xarif qilib so’zni print qilin." 189 | ] 190 | }, 191 | { 192 | "cell_type": "code", 193 | "execution_count": 23, 194 | "id": "48595fe1-740e-46c7-b8af-ab6bef2e4c68", 195 | "metadata": {}, 196 | "outputs": [ 197 | { 198 | "name": "stdin", 199 | "output_type": "stream", 200 | "text": [ 201 | "So'z kiriting: maxammadsoliyev u\n" 202 | ] 203 | }, 204 | { 205 | "name": "stdout", 206 | "output_type": "stream", 207 | "text": [ 208 | "Maxammadsoliyev U\n" 209 | ] 210 | } 211 | ], 212 | "source": [ 213 | "soz = input(\"So'z kiriting: \")\n", 214 | "\n", 215 | "soz = soz[0].upper() + soz[1:-1] + soz[-1].upper()\n", 216 | "print(soz)" 217 | ] 218 | }, 219 | { 220 | "cell_type": "markdown", 221 | "id": "8139405f-a24e-43b7-b2d7-6b69fd23ed25", 222 | "metadata": {}, 223 | "source": [ 224 | "### 7. So’z kiritilgan katta va kichi hariflar bilan. Katta harifni kichikga, kichik katta ozgartirib print qiling." 225 | ] 226 | }, 227 | { 228 | "cell_type": "code", 229 | "execution_count": 24, 230 | "id": "693f91f4-2a43-49c6-8540-21e2317350ef", 231 | "metadata": {}, 232 | "outputs": [ 233 | { 234 | "name": "stdin", 235 | "output_type": "stream", 236 | "text": [ 237 | "So'z kiriting: MAxaMmAdsoLiyEV\n" 238 | ] 239 | }, 240 | { 241 | "name": "stdout", 242 | "output_type": "stream", 243 | "text": [ 244 | "maXAmMaDSOlIYev\n" 245 | ] 246 | } 247 | ], 248 | "source": [ 249 | "soz = input(\"So'z kiriting: \")\n", 250 | "\n", 251 | "for i in range(len(soz)):\n", 252 | " if soz[i].isupper():\n", 253 | " soz = soz[:i] + soz[i].lower() + soz[i+1:]\n", 254 | " elif soz[i].islower():\n", 255 | " soz = soz[:i] + soz[i].upper() + soz[i+1:]\n", 256 | " \n", 257 | "print(soz)" 258 | ] 259 | }, 260 | { 261 | "cell_type": "markdown", 262 | "id": "8dde39e5-8c08-421c-8051-7115f4a978c3", 263 | "metadata": {}, 264 | "source": [ 265 | "### 8. So’z kiritilgan uni birinchi harifi “S” oxirgisi esa “R” ekanligni aniqlang." 266 | ] 267 | }, 268 | { 269 | "cell_type": "code", 270 | "execution_count": 27, 271 | "id": "b70e5adc-6733-431b-aa73-6cfb421cec79", 272 | "metadata": {}, 273 | "outputs": [ 274 | { 275 | "name": "stdin", 276 | "output_type": "stream", 277 | "text": [ 278 | "So'z kiriting: SattoR\n" 279 | ] 280 | }, 281 | { 282 | "name": "stdout", 283 | "output_type": "stream", 284 | "text": [ 285 | "Kiritilgan so'zning birinchi harifi “S” oxirgisi esa “R” \n" 286 | ] 287 | } 288 | ], 289 | "source": [ 290 | "soz = input(\"So'z kiriting: \")\n", 291 | "\n", 292 | "if soz[0] == \"S\" and soz[-1] == \"R\":\n", 293 | " print(\"Kiritilgan so'zning birinchi harifi “S” oxirgisi esa “R” \")" 294 | ] 295 | }, 296 | { 297 | "cell_type": "markdown", 298 | "id": "d699bb9b-5549-4336-be65-33415dc997c1", 299 | "metadata": {}, 300 | "source": [ 301 | "### 9. So’z kiritilgan uni birinchi harifi “S” oxirgisi esa “R” teng emasligini aniqlang" 302 | ] 303 | }, 304 | { 305 | "cell_type": "code", 306 | "execution_count": 28, 307 | "id": "5f3cb008-b3c7-4377-ac63-57a4d9d4962b", 308 | "metadata": {}, 309 | "outputs": [ 310 | { 311 | "name": "stdin", 312 | "output_type": "stream", 313 | "text": [ 314 | "So'z kiriting: assdfgfhhggsdfghjgfdsgh\n" 315 | ] 316 | }, 317 | { 318 | "name": "stdout", 319 | "output_type": "stream", 320 | "text": [ 321 | "Kiritilgan so'zning birinchi harifi “S” oxirgisi esa “R” emas\n" 322 | ] 323 | } 324 | ], 325 | "source": [ 326 | "soz = input(\"So'z kiriting: \")\n", 327 | "\n", 328 | "if soz[0] != \"S\" and soz[-1] != \"R\":\n", 329 | " print(\"Kiritilgan so'zning birinchi harifi “S” oxirgisi esa “R” emas\")" 330 | ] 331 | } 332 | ], 333 | "metadata": { 334 | "kernelspec": { 335 | "display_name": "Python 3 (ipykernel)", 336 | "language": "python", 337 | "name": "python3" 338 | }, 339 | "language_info": { 340 | "codemirror_mode": { 341 | "name": "ipython", 342 | "version": 3 343 | }, 344 | "file_extension": ".py", 345 | "mimetype": "text/x-python", 346 | "name": "python", 347 | "nbconvert_exporter": "python", 348 | "pygments_lexer": "ipython3", 349 | "version": "3.9.7" 350 | } 351 | }, 352 | "nbformat": 4, 353 | "nbformat_minor": 5 354 | } 355 | -------------------------------------------------------------------------------- /python/6-dars-for-loop-3.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "cd4088d5-09b9-4137-9f51-64175cd5f8b7", 6 | "metadata": {}, 7 | "source": [ 8 | "### 1. Uzunligi teng bo'lgan ikkita so'z kiritilgan. Misol uchun A = \"olma\" B = \"anor\". Sikl oraqlik yangi so'z tuzing. Natija: C = \"oalnmoar\", yani A 1-si va B 1-si C boshiga qoshildi C = \"oa.yani A 2-si va B 2-si C boshiga qoshildi C = \"oaln. ...." 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": 1, 14 | "id": "53b4ba8e-61eb-4bc3-a4ef-20fd036452ba", 15 | "metadata": {}, 16 | "outputs": [ 17 | { 18 | "name": "stdout", 19 | "output_type": "stream", 20 | "text": [ 21 | "oalnmoar\n" 22 | ] 23 | } 24 | ], 25 | "source": [ 26 | "a = 'olma'\n", 27 | "b = 'anor'\n", 28 | "c = ''\n", 29 | "\n", 30 | "for i in range(len(a)):\n", 31 | " c += a[i] + b[i]\n", 32 | " \n", 33 | "print(c)" 34 | ] 35 | }, 36 | { 37 | "cell_type": "markdown", 38 | "id": "e249df5d-12e9-4765-86a8-d8a0cd8bb090", 39 | "metadata": {}, 40 | "source": [ 41 | "### 2. So'z berilgan \"d!v!l@p!r\" -> \"developer\" korinishiga o'tkazing." 42 | ] 43 | }, 44 | { 45 | "cell_type": "code", 46 | "execution_count": 6, 47 | "id": "782bf169-2fac-469e-9395-29f57c2378a3", 48 | "metadata": {}, 49 | "outputs": [ 50 | { 51 | "data": { 52 | "text/plain": [ 53 | "'developer'" 54 | ] 55 | }, 56 | "execution_count": 6, 57 | "metadata": {}, 58 | "output_type": "execute_result" 59 | } 60 | ], 61 | "source": [ 62 | "soz = 'd!v!l@p!r'\n", 63 | "soz.replace('!', 'e').replace('@', 'o')" 64 | ] 65 | }, 66 | { 67 | "cell_type": "markdown", 68 | "id": "9d213cf7-35e5-4dd6-a1ab-3d11368edb9f", 69 | "metadata": {}, 70 | "source": [ 71 | "### 3. So'z kiritilgan, keyin esa harif kiritilgan, so'zda shu harifdan netcha borligni aniqlang." 72 | ] 73 | }, 74 | { 75 | "cell_type": "code", 76 | "execution_count": 9, 77 | "id": "517b9fc1-9a5e-4204-9468-3f0632d63609", 78 | "metadata": {}, 79 | "outputs": [ 80 | { 81 | "name": "stdin", 82 | "output_type": "stream", 83 | "text": [ 84 | "So'z kiriting: Maxammadsoliyev\n", 85 | "Harf kiriting: m\n" 86 | ] 87 | }, 88 | { 89 | "name": "stdout", 90 | "output_type": "stream", 91 | "text": [ 92 | "maxammadsoliyev da m harfidan 3 ta bor\n" 93 | ] 94 | } 95 | ], 96 | "source": [ 97 | "soz = input(\"So'z kiriting: \").lower()\n", 98 | "harf = input(\"Harf kiriting: \").lower()\n", 99 | "\n", 100 | "count = 0\n", 101 | "for i in soz:\n", 102 | " if i == harf:\n", 103 | " count += 1\n", 104 | "print(f\"{soz} da {harf} harfidan {count} ta bor\")" 105 | ] 106 | }, 107 | { 108 | "cell_type": "markdown", 109 | "id": "38c92ae5-aeac-4f42-9274-9227d36b342f", 110 | "metadata": {}, 111 | "source": [ 112 | "### 4. Katta va kichik hariflar bilan so'z kiritilgan. Katta hariflarni aloxida so'z qilib print qiling. Misol uchun: \"TeLefOn\". Natija: \"TLO\"" 113 | ] 114 | }, 115 | { 116 | "cell_type": "code", 117 | "execution_count": 10, 118 | "id": "f2194714-10a5-4c11-ad66-95808bc01c1e", 119 | "metadata": {}, 120 | "outputs": [ 121 | { 122 | "name": "stdin", 123 | "output_type": "stream", 124 | "text": [ 125 | "So'z kiriting: TeeleFOn\n" 126 | ] 127 | }, 128 | { 129 | "name": "stdout", 130 | "output_type": "stream", 131 | "text": [ 132 | "TFO\n" 133 | ] 134 | } 135 | ], 136 | "source": [ 137 | "soz = input(\"So'z kiriting: \")\n", 138 | "new = ''\n", 139 | "\n", 140 | "for i in soz:\n", 141 | " if i.isupper():\n", 142 | " new += i\n", 143 | "print(new)" 144 | ] 145 | }, 146 | { 147 | "cell_type": "markdown", 148 | "id": "0015ee9e-15fc-4481-8362-5bbac1ee6cf9", 149 | "metadata": {}, 150 | "source": [ 151 | "### 5. Katta va kichik hariflar bilan so'z kiritilgan. Kichik hariflarni aloxida so'z qilib print qiling. Misol uchun: \"TeLefOn\". Natija: \"eefn\"" 152 | ] 153 | }, 154 | { 155 | "cell_type": "code", 156 | "execution_count": 11, 157 | "id": "e807f3f9-60bb-40cd-9f46-efcce2844735", 158 | "metadata": {}, 159 | "outputs": [ 160 | { 161 | "name": "stdin", 162 | "output_type": "stream", 163 | "text": [ 164 | "So'z kiriting: TeLefOn\n" 165 | ] 166 | }, 167 | { 168 | "name": "stdout", 169 | "output_type": "stream", 170 | "text": [ 171 | "eefn\n" 172 | ] 173 | } 174 | ], 175 | "source": [ 176 | "soz = input(\"So'z kiriting: \")\n", 177 | "new = ''\n", 178 | "\n", 179 | "for i in soz:\n", 180 | " if i.islower():\n", 181 | " new += i\n", 182 | "print(new)" 183 | ] 184 | }, 185 | { 186 | "cell_type": "markdown", 187 | "id": "6a3a52e9-0ce0-48ec-aba4-d069a21c7809", 188 | "metadata": {}, 189 | "source": [ 190 | "### 6. Katta va kichik hariflar bilan so'z kiritilgan. 4 va 5 vazifani birlashtirgan holda. Katta harifli so'zlarni boshiga kichik harifli so'zlarni oxiriga qoyib print qiling. Misol uchun: \"TeLefOn\". Natija: \"TLOeefn\"" 191 | ] 192 | }, 193 | { 194 | "cell_type": "code", 195 | "execution_count": 13, 196 | "id": "8d2f776d-bcd6-4056-b78e-c91afaedd1f0", 197 | "metadata": {}, 198 | "outputs": [ 199 | { 200 | "name": "stdin", 201 | "output_type": "stream", 202 | "text": [ 203 | "So'z kiriting: TeLefOn\n" 204 | ] 205 | }, 206 | { 207 | "name": "stdout", 208 | "output_type": "stream", 209 | "text": [ 210 | "TLOeefn\n" 211 | ] 212 | } 213 | ], 214 | "source": [ 215 | "soz = input(\"So'z kiriting: \")\n", 216 | "up = ''\n", 217 | "low = ''\n", 218 | "\n", 219 | "for i in soz:\n", 220 | " if i.islower():\n", 221 | " low += i\n", 222 | " else:\n", 223 | " up += i\n", 224 | " \n", 225 | "print(up+low)" 226 | ] 227 | } 228 | ], 229 | "metadata": { 230 | "kernelspec": { 231 | "display_name": "Python 3 (ipykernel)", 232 | "language": "python", 233 | "name": "python3" 234 | }, 235 | "language_info": { 236 | "codemirror_mode": { 237 | "name": "ipython", 238 | "version": 3 239 | }, 240 | "file_extension": ".py", 241 | "mimetype": "text/x-python", 242 | "name": "python", 243 | "nbconvert_exporter": "python", 244 | "pygments_lexer": "ipython3", 245 | "version": "3.9.7" 246 | } 247 | }, 248 | "nbformat": 4, 249 | "nbformat_minor": 5 250 | } 251 | -------------------------------------------------------------------------------- /python/7-dars-while-x-va-0-oyini.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 23, 6 | "metadata": { 7 | "collapsed": true 8 | }, 9 | "outputs": [ 10 | { 11 | "name": "stdout", 12 | "output_type": "stream", 13 | "text": [ 14 | "1 | 2 | 3\n", 15 | "---------\n", 16 | "4 | 5 | 6\n", 17 | "---------\n", 18 | "7 | 8 | 9\n", 19 | "\n", 20 | "\n", 21 | "\n", 22 | "x | 2 | 3\n", 23 | "---------\n", 24 | "4 | 5 | 6\n", 25 | "---------\n", 26 | "7 | 8 | 9\n", 27 | "\n", 28 | "\n", 29 | "\n", 30 | "x | y | 3\n", 31 | "---------\n", 32 | "4 | 5 | 6\n", 33 | "---------\n", 34 | "7 | 8 | 9\n", 35 | "\n", 36 | "\n", 37 | "\n", 38 | "x | y | y\n", 39 | "---------\n", 40 | "4 | 5 | 6\n", 41 | "---------\n", 42 | "7 | 8 | 9\n", 43 | "\n", 44 | "\n", 45 | "\n", 46 | "x | y | x\n", 47 | "---------\n", 48 | "4 | 5 | 6\n", 49 | "---------\n", 50 | "7 | 8 | 9\n", 51 | "\n", 52 | "\n", 53 | "\n", 54 | "x | y | x\n", 55 | "---------\n", 56 | "y | 5 | 6\n", 57 | "---------\n", 58 | "7 | 8 | 9\n", 59 | "\n", 60 | "\n", 61 | "\n" 62 | ] 63 | } 64 | ], 65 | "source": [ 66 | "t = [1, 2, 3, 4, 5, 6, 7, 8, 9]\n", 67 | "count = 0\n", 68 | "\n", 69 | "while count < 9:\n", 70 | " while True:\n", 71 | " if count == 9:\n", 72 | " break\n", 73 | " x = int(input(\"x = \")) - 1\n", 74 | " if t[x] == 'x' or t[x] == 'o':\n", 75 | " continue\n", 76 | " t[x] = 'x'\n", 77 | " count += 1\n", 78 | " print(f\"{t[0]} | {t[1]} | {t[2]}\", f\"{t[3]} | {t[4]} | {t[5]}\", f\"{t[6]} | {t[7]} | {t[8]}\",\n", 79 | " sep='\\n---------\\n')\n", 80 | " print('\\n')\n", 81 | " break\n", 82 | "\n", 83 | " if t[0] == t[1] == t[2] == \"x\" or t[3] == t[4] == t[5] == \"x\" or t[6] == t[7] == t[8] == \"x\" or \\\n", 84 | " t[0] == t[3] == t[6] == \"x\" or t[1] == t[4] == t[7] == \"x\" or t[2] == t[5] == t[8] == \"x\" or \\\n", 85 | " t[0] == t[4] == t[8] == \"x\" or t[2] == t[4] == t[6] == \"x\":\n", 86 | " print(\"x yutdi!!!\")\n", 87 | " break\n", 88 | "\n", 89 | " while True:\n", 90 | " if count == 9:\n", 91 | " break\n", 92 | "\n", 93 | " y = int(input(\"o = \")) - 1\n", 94 | " if t[y] == 'o' or t[y] == 'x':\n", 95 | " continue\n", 96 | " t[y] = 'o'\n", 97 | " count += 1\n", 98 | " print(f\"{t[0]} | {t[1]} | {t[2]}\", f\"{t[3]} | {t[4]} | {t[5]}\", f\"{t[6]} | {t[7]} | {t[8]}\",\n", 99 | " sep='\\n---------\\n')\n", 100 | " print('\\n')\n", 101 | " break\n", 102 | "\n", 103 | " if t[0] == t[1] == t[2] == \"o\" or t[3] == t[4] == t[5] == \"o\" or t[6] == t[7] == t[8] == \"o\" or \\\n", 104 | " t[0] == t[3] == t[6] == \"o\" or t[1] == t[4] == t[7] == \"o\" or t[2] == t[5] == t[8] == \"o\" or \\\n", 105 | " t[0] == t[4] == t[8] == \"o\" or t[2] == t[4] == t[6] == \"o\":\n", 106 | " print(\"o yutdi!!!\")\n", 107 | " break\n", 108 | "else:\n", 109 | " print(\"Durrang!!!\")\n" 110 | ] 111 | }, 112 | { 113 | "cell_type": "code", 114 | "execution_count": 3, 115 | "outputs": [ 116 | { 117 | "name": "stdout", 118 | "output_type": "stream", 119 | "text": [ 120 | "[[1, 2, 3], [4, 5, 6], [7, 8, 9]]\n" 121 | ] 122 | } 123 | ], 124 | "source": [ 125 | "g" 126 | ], 127 | "metadata": { 128 | "collapsed": false, 129 | "pycharm": { 130 | "name": "#%%\n" 131 | } 132 | } 133 | }, 134 | { 135 | "cell_type": "code", 136 | "execution_count": null, 137 | "outputs": [], 138 | "source": [], 139 | "metadata": { 140 | "collapsed": false, 141 | "pycharm": { 142 | "name": "#%%\n" 143 | } 144 | } 145 | } 146 | ], 147 | "metadata": { 148 | "kernelspec": { 149 | "display_name": "Python 3", 150 | "language": "python", 151 | "name": "python3" 152 | }, 153 | "language_info": { 154 | "codemirror_mode": { 155 | "name": "ipython", 156 | "version": 2 157 | }, 158 | "file_extension": ".py", 159 | "mimetype": "text/x-python", 160 | "name": "python", 161 | "nbconvert_exporter": "python", 162 | "pygments_lexer": "ipython2", 163 | "version": "2.7.6" 164 | } 165 | }, 166 | "nbformat": 4, 167 | "nbformat_minor": 0 168 | } -------------------------------------------------------------------------------- /python/7-dars-x_o_game.py: -------------------------------------------------------------------------------- 1 | t = [1, 2, 3, 4, 5, 6, 7, 8, 9] 2 | count = 0 3 | 4 | while count < 9: 5 | while True: 6 | if count == 9: 7 | break 8 | 9 | x = int(input("x = ")) - 1 10 | if t[x] == 'x' or t[x] == 'o': 11 | continue 12 | t[x] = 'x' 13 | count += 1 14 | print(f"{t[0]} | {t[1]} | {t[2]}", f"{t[3]} | {t[4]} | {t[5]}", f"{t[6]} | {t[7]} | {t[8]}", 15 | sep='\n---------\n') 16 | print('\n') 17 | break 18 | 19 | if t[0] == t[1] == t[2] == "x" or t[3] == t[4] == t[5] == "x" or t[6] == t[7] == t[8] == "x" or \ 20 | t[0] == t[3] == t[6] == "x" or t[1] == t[4] == t[7] == "x" or t[2] == t[5] == t[8] == "x" or \ 21 | t[0] == t[4] == t[8] == "x" or t[2] == t[4] == t[6] == "x": 22 | print("x yutdi!!!") 23 | break 24 | 25 | while True: 26 | if count == 9: 27 | break 28 | 29 | y = int(input("o = ")) - 1 30 | if t[y] == 'o' or t[y] == 'x': 31 | continue 32 | t[y] = 'o' 33 | count += 1 34 | print(f"{t[0]} | {t[1]} | {t[2]}", f"{t[3]} | {t[4]} | {t[5]}", f"{t[6]} | {t[7]} | {t[8]}", 35 | sep='\n---------\n') 36 | print('\n') 37 | break 38 | 39 | if t[0] == t[1] == t[2] == "o" or t[3] == t[4] == t[5] == "o" or t[6] == t[7] == t[8] == "o" or \ 40 | t[0] == t[3] == t[6] == "o" or t[1] == t[4] == t[7] == "o" or t[2] == t[5] == t[8] == "o" or \ 41 | t[0] == t[4] == t[8] == "o" or t[2] == t[4] == t[6] == "o": 42 | print("o yutdi!!!") 43 | break 44 | else: 45 | print("Durrang!!!") 46 | -------------------------------------------------------------------------------- /python/9-dars-takrorlash.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "source": [ 6 | "# Funksiya" 7 | ], 8 | "metadata": { 9 | "collapsed": false, 10 | "pycharm": { 11 | "name": "#%% md\n" 12 | } 13 | } 14 | }, 15 | { 16 | "cell_type": "code", 17 | "execution_count": 2, 18 | "outputs": [ 19 | { 20 | "name": "stdout", 21 | "output_type": "stream", 22 | "text": [ 23 | "Hello world!\n" 24 | ] 25 | } 26 | ], 27 | "source": [ 28 | "def first_func():\n", 29 | " print(\"Hello world!\")\n", 30 | "\n", 31 | "\n", 32 | "first_func()" 33 | ], 34 | "metadata": { 35 | "collapsed": false, 36 | "pycharm": { 37 | "name": "#%%\n" 38 | } 39 | } 40 | }, 41 | { 42 | "cell_type": "code", 43 | "execution_count": 4, 44 | "outputs": [ 45 | { 46 | "name": "stdout", 47 | "output_type": "stream", 48 | "text": [ 49 | "Good bye world!\n" 50 | ] 51 | } 52 | ], 53 | "source": [ 54 | "def bye_func():\n", 55 | " print(\"Good bye world!\")\n", 56 | "\n", 57 | "\n", 58 | "bye_func()" 59 | ], 60 | "metadata": { 61 | "collapsed": false, 62 | "pycharm": { 63 | "name": "#%%\n" 64 | } 65 | } 66 | }, 67 | { 68 | "cell_type": "code", 69 | "execution_count": 7, 70 | "outputs": [ 71 | { 72 | "name": "stdout", 73 | "output_type": "stream", 74 | "text": [ 75 | "25\n" 76 | ] 77 | } 78 | ], 79 | "source": [ 80 | "def add(a, b):\n", 81 | " return a + b\n", 82 | "\n", 83 | "\n", 84 | "print(add(12, 13))" 85 | ], 86 | "metadata": { 87 | "collapsed": false, 88 | "pycharm": { 89 | "name": "#%%\n" 90 | } 91 | } 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": 9, 96 | "outputs": [ 97 | { 98 | "name": "stdout", 99 | "output_type": "stream", 100 | "text": [ 101 | "('salom', 'hammaga', 'meni', \"qo'llab\")\n" 102 | ] 103 | } 104 | ], 105 | "source": [ 106 | "def my_func(*kids):\n", 107 | " print(kids)\n", 108 | "\n", 109 | "\n", 110 | "my_func('salom', 'hammaga', 'meni', \"qo'llab\")" 111 | ], 112 | "metadata": { 113 | "collapsed": false, 114 | "pycharm": { 115 | "name": "#%%\n" 116 | } 117 | } 118 | }, 119 | { 120 | "cell_type": "code", 121 | "execution_count": 11, 122 | "outputs": [ 123 | { 124 | "name": "stdout", 125 | "output_type": "stream", 126 | "text": [ 127 | "{'ism': 'Olim', 'familiya': 'Akbarov', 'yosh': 13}\n" 128 | ] 129 | } 130 | ], 131 | "source": [ 132 | "def my_func1(**kid):\n", 133 | " print(kid)\n", 134 | "\n", 135 | "\n", 136 | "my_func1(ism='Olim', familiya='Akbarov', yosh=13)" 137 | ], 138 | "metadata": { 139 | "collapsed": false, 140 | "pycharm": { 141 | "name": "#%%\n" 142 | } 143 | } 144 | }, 145 | { 146 | "cell_type": "code", 147 | "execution_count": 12, 148 | "outputs": [ 149 | { 150 | "name": "stdout", 151 | "output_type": "stream", 152 | "text": [ 153 | "\n", 154 | " ism: Umidbek\n", 155 | " familiya: Maxammadsoliyev\n", 156 | " yosh: 19\n", 157 | " \n" 158 | ] 159 | } 160 | ], 161 | "source": [ 162 | "def user_data(first_name, last_name, age):\n", 163 | " print(f\"\"\"\n", 164 | " ism: {first_name}\n", 165 | " familiya: {last_name}\n", 166 | " yosh: {age}\n", 167 | " \"\"\")\n", 168 | "\n", 169 | "\n", 170 | "user_data('Umidbek', \"Maxammadsoliyev\", 19)" 171 | ], 172 | "metadata": { 173 | "collapsed": false, 174 | "pycharm": { 175 | "name": "#%%\n" 176 | } 177 | } 178 | }, 179 | { 180 | "cell_type": "code", 181 | "execution_count": 34, 182 | "outputs": [ 183 | { 184 | "name": "stdout", 185 | "output_type": "stream", 186 | "text": [ 187 | "{'aprel': 15000}\n" 188 | ] 189 | } 190 | ], 191 | "source": [ 192 | "def big_sales(sales):\n", 193 | " my_max = max(sales.values())\n", 194 | " i = list(sales.values()).index(my_max)\n", 195 | " key = list(sales.keys())[i]\n", 196 | " return {key: my_max}\n", 197 | "\n", 198 | "\n", 199 | "sales1 = {\n", 200 | " \"yanvar\": 12000,\n", 201 | " \"mart\": 6000,\n", 202 | " \"aprel\": 15000,\n", 203 | " \"sentabr\": 9000,\n", 204 | " \"dekabr\": 10000,\n", 205 | "}\n", 206 | "\n", 207 | "print(big_sales(sales1))" 208 | ], 209 | "metadata": { 210 | "collapsed": false, 211 | "pycharm": { 212 | "name": "#%%\n" 213 | } 214 | } 215 | }, 216 | { 217 | "cell_type": "markdown", 218 | "source": [], 219 | "metadata": { 220 | "collapsed": false 221 | } 222 | }, 223 | { 224 | "cell_type": "markdown", 225 | "source": [ 226 | "### So'z berilgan \"d!v!l@p!r\" -> \"developer\" korinishiga o'tkazing." 227 | ], 228 | "metadata": { 229 | "collapsed": false, 230 | "pycharm": { 231 | "name": "#%% md\n" 232 | } 233 | } 234 | }, 235 | { 236 | "cell_type": "code", 237 | "execution_count": 42, 238 | "outputs": [ 239 | { 240 | "data": { 241 | "text/plain": "'developer'" 242 | }, 243 | "execution_count": 42, 244 | "metadata": {}, 245 | "output_type": "execute_result" 246 | } 247 | ], 248 | "source": [ 249 | "text = \"d!v!l@p!r\"\n", 250 | "\n", 251 | "x = \"!@\"\n", 252 | "y = \"eo\"\n", 253 | "\n", 254 | "table = text.maketrans(x, y)\n", 255 | "text.translate(table)\n", 256 | "# print(text)" 257 | ], 258 | "metadata": { 259 | "collapsed": false, 260 | "pycharm": { 261 | "name": "#%%\n" 262 | } 263 | } 264 | }, 265 | { 266 | "cell_type": "code", 267 | "execution_count": 43, 268 | "outputs": [ 269 | { 270 | "name": "stdout", 271 | "output_type": "stream", 272 | "text": [ 273 | "LKHSGFDZFX" 274 | ] 275 | } 276 | ], 277 | "source": [ 278 | "# matn\n", 279 | "\n", 280 | "matn = input(\"text: \")\n", 281 | "\n", 282 | "for x in matn:\n", 283 | " if x.isupper():\n", 284 | " print(x, end='')" 285 | ], 286 | "metadata": { 287 | "collapsed": false, 288 | "pycharm": { 289 | "name": "#%%\n" 290 | } 291 | } 292 | }, 293 | { 294 | "cell_type": "markdown", 295 | "source": [ 296 | "### 7. digit_count_and_sum(word) - bu funksiya \"word\" ni ichidagi raqamni aniqlab ularni yig'indisini va nechtaligini print qilsin." 297 | ], 298 | "metadata": { 299 | "collapsed": false, 300 | "pycharm": { 301 | "name": "#%% md\n" 302 | } 303 | } 304 | }, 305 | { 306 | "cell_type": "code", 307 | "execution_count": 47, 308 | "outputs": [ 309 | { 310 | "name": "stdout", 311 | "output_type": "stream", 312 | "text": [ 313 | "yigindi: 15 soni: 5\n" 314 | ] 315 | } 316 | ], 317 | "source": [ 318 | "def digit_count_and_sum(word):\n", 319 | " k = 0\n", 320 | " s = 0\n", 321 | " for i in word:\n", 322 | " if i.isdigit():\n", 323 | " s += int(i)\n", 324 | " k += 1\n", 325 | "\n", 326 | " print('yigindi:', s, 'soni:', k)\n", 327 | "\n", 328 | "digit_count_and_sum(\"q1w2e3r4t5y\")" 329 | ], 330 | "metadata": { 331 | "collapsed": false, 332 | "pycharm": { 333 | "name": "#%%\n" 334 | } 335 | } 336 | }, 337 | { 338 | "cell_type": "code", 339 | "execution_count": null, 340 | "outputs": [], 341 | "source": [], 342 | "metadata": { 343 | "collapsed": false, 344 | "pycharm": { 345 | "name": "#%%\n" 346 | } 347 | } 348 | } 349 | ], 350 | "metadata": { 351 | "kernelspec": { 352 | "display_name": "Python 3", 353 | "language": "python", 354 | "name": "python3" 355 | }, 356 | "language_info": { 357 | "codemirror_mode": { 358 | "name": "ipython", 359 | "version": 2 360 | }, 361 | "file_extension": ".py", 362 | "mimetype": "text/x-python", 363 | "name": "python", 364 | "nbconvert_exporter": "python", 365 | "pygments_lexer": "ipython2", 366 | "version": "2.7.6" 367 | } 368 | }, 369 | "nbformat": 4, 370 | "nbformat_minor": 0 371 | } --------------------------------------------------------------------------------