├── .gitignore ├── Advanced-Questions ├── 01-monty-hall-problem │ ├── Python │ │ └── main.py │ │ │ └── main.py │ └── README.md ├── 02-call-center │ ├── Python │ │ └── main.py │ ├── README.md │ └── docs │ │ ├── answer.png │ │ └── question.png ├── 03-hash-cracker │ ├── Python │ │ └── main.py │ ├── passwords.csv │ └── readme.md ├── 04-binary-search │ ├── Python │ │ └── app.py │ └── README.md └── 05-merge-sorted-array │ └── README.md ├── LICENSE ├── Medium-Questions ├── 01-even-Or-odd-(Fa) │ ├── C# │ │ └── One.cs │ ├── C │ │ └── one.c │ ├── Lua │ │ └── one.lua │ ├── Node │ │ ├── package-lock.json │ │ ├── package.json │ │ └── src │ │ │ └── one.js │ ├── Php │ │ └── One.php │ ├── README.md │ ├── python │ │ └── One.py │ └── rust │ │ ├── Cargo.lock │ │ ├── Cargo.toml │ │ └── src │ │ └── main.rs ├── 02-Star-Number-(Fa) │ ├── C# │ │ └── Two.cs │ ├── C │ │ └── Two.c │ ├── Lua │ │ └── two.lua │ ├── Node │ │ └── Two.js │ ├── Python │ │ └── two.py │ └── README.md ├── 03-Binary-Star-(Fa) │ ├── C# │ │ ├── Three-1.cs │ │ ├── Three-2.cs │ │ └── Three-3.cs │ ├── JavaScript │ │ ├── Three.html │ │ └── Three.js │ ├── Python │ │ ├── three-1.py │ │ ├── three-2.py │ │ └── three-3.py │ └── README.md ├── 04-Bubble-Sort-(Fa) │ ├── C# │ │ └── four.cs │ ├── Javascript │ │ ├── Four.js │ │ └── four.html │ ├── Python │ │ └── Four.py │ ├── README.md │ └── img │ │ └── 4.png ├── 05-algorithm-odd │ ├── C# │ │ └── Five.cs │ ├── C │ │ └── five.c │ ├── JavaScript │ │ ├── app.js │ │ └── index.html │ ├── Python │ │ └── Five.py │ └── README.md ├── 06-circle-Area │ ├── C# │ │ └── six.cs │ ├── C │ │ └── Six.c │ ├── JavaScript │ │ └── index.html │ ├── Python │ │ └── six.py │ └── README.md ├── 07-Reverse-Name │ ├── C# │ │ └── seven.cs │ ├── C │ │ └── seven.c │ ├── JavaScript │ │ ├── seven.html │ │ └── seven.js │ ├── Python │ │ └── seven.py │ └── README.md ├── 08-Ascii-input │ ├── C# │ │ └── eight.cs │ ├── Python │ │ └── eight.py │ └── README.md ├── 09-DateTime │ ├── C# │ │ └── app.cs │ ├── JavaScript │ │ └── app.js │ ├── Python │ │ └── Nine.py │ └── README.md ├── 10-tuple-List │ ├── Python │ │ └── Ten.py │ └── README.md ├── 11-Three-Sum-N │ ├── Python │ │ └── Eleven.py │ └── README.md ├── 12-Calender │ ├── Python │ │ └── twelve.py │ └── README.md ├── 13-Days-Calculator │ ├── C# │ │ └── app.cs │ ├── JavaScript │ │ └── app.js │ ├── Python │ │ └── thirteen.py │ └── README.md ├── 14-value-sphere │ ├── C# │ │ └── app.cs │ ├── Python │ │ └── Fourteen.py │ └── README.md ├── 15-Triangle-Area │ ├── C# │ │ └── fifteen.cs │ ├── C │ │ └── fifteen.c │ ├── Python │ │ └── fifteen.py │ └── README.md ├── 16-Missing-Number │ ├── Python │ │ └── sixteen.py │ └── README.md ├── 17-Repetitions │ ├── Python │ │ └── Seventeen.py │ └── README.md ├── 18-Sum-Cube-Number │ ├── Python │ │ └── eighteen.py │ └── README.md ├── 19-Missing-Color │ ├── Python │ │ └── NineTeen.py │ └── README.md ├── 20-Sum-Integer │ ├── C# │ │ └── twenty.cs │ ├── JavaScript │ │ └── app.js │ ├── Python │ │ └── twenty.py │ └── README.md ├── 21-ip-validate │ ├── JavaScript │ │ └── app.js │ ├── Python │ │ └── ip.py │ └── README.md ├── 22-Number-2-Bin │ ├── Python │ │ └── Nm2Bin.py │ └── README.md ├── 23-body-mass-index │ ├── Python │ │ └── Twenty-Three.py │ └── README.md ├── 24-pass-algorithm │ ├── Python │ │ ├── Twenty-Four.py │ │ └── requirement.txt │ └── README.md ├── 25-Permutations │ └── README.md ├── 26-String-gen │ ├── Python │ │ └── Twenty-six.py │ └── README.md ├── 27-Math-machine │ ├── Python │ │ └── Twenty-seven.py │ └── README.md ├── 28-Find-19 │ ├── JavaScript │ │ └── app.js │ ├── Python │ │ └── twenty-eight.py │ └── README.md ├── 30-Piles │ ├── Python │ │ └── thirty.py │ └── README.md ├── 31-Middle-word │ ├── Python │ │ └── Main.py │ └── README.md ├── 32-Pass-cracker │ ├── Python │ │ └── pass-cracker.py │ └── README.md ├── 33-Smallest-Largest │ ├── Python │ │ └── Main.py │ └── README.md ├── 34-Bitstring │ ├── C# │ │ └── Main.cs │ ├── Python │ │ └── Main.py │ └── README.md ├── 35-students-Grade │ ├── Python │ │ └── students-Grade.py │ └── README.md ├── 36-perfect-number │ ├── Python │ │ └── perfect_number.py │ └── README.md ├── 37-avg-Employee │ ├── Python │ │ └── employee.py │ ├── doc │ │ └── Capture.PNG │ └── readme.md ├── 38-shop-percentage │ ├── Python │ │ └── shop.py │ ├── doc │ │ ├── output.PNG │ │ └── question.PNG │ └── readme.md ├── 39-Rock-Paper-Scissors │ ├── Python │ │ └── app.py │ ├── doc │ │ ├── output.png │ │ └── question.png │ └── readme.md ├── 40-Car-20 │ ├── Python │ │ └── main.py │ ├── doc │ │ ├── output.png │ │ └── question.png │ └── readme.md ├── 41-Radical-factorial │ ├── Python │ │ └── math.py │ ├── doc │ │ └── question.png │ └── readme.md ├── 42-Multiples of 3 or 5 │ ├── Python │ │ └── app.py │ └── README.md ├── 43-Even Fibonacci numbers │ ├── Python │ │ └── app.py │ └── readme.md ├── 44-Cipher-Location │ ├── Python │ │ └── app.py │ └── README.md ├── 45-Number-methods │ ├── Doc │ │ ├── ans1.png │ │ ├── ans2.png │ │ ├── ans3.png │ │ ├── ans4.png │ │ └── question.png │ ├── Python │ │ └── main.py │ └── README.md ├── 46-teacher's-salary │ ├── README.md │ ├── doc │ │ ├── answer.png │ │ └── question.png │ └── python │ │ └── main.py ├── 47-power-of-n │ ├── Python │ │ └── main.py │ ├── doc │ │ ├── answer.png │ │ └── question.png │ └── readme.md ├── 48-n-Div-Fac(n) │ ├── Python │ │ └── main.py │ ├── doc │ │ ├── answer.png │ │ └── question.png │ └── readme.md ├── 49-multiple-without-multiple │ ├── Python │ │ └── main.py │ ├── doc │ │ ├── answer.png │ │ └── question.png │ └── readme.md ├── 50-n-factorial │ ├── doc │ │ ├── answer.png │ │ └── question.png │ ├── python │ │ └── main.py │ └── readme.md ├── 51-sum-of-factorial │ ├── doc │ │ ├── answer.png │ │ └── question.png │ ├── python │ │ └── main.py │ └── readme.md ├── 52-div-of-factorial │ ├── doc │ │ ├── answer.png │ │ └── question.png │ ├── python │ │ └── main.py │ └── readme.md ├── 53-fibonacci-n's │ ├── doc │ │ ├── answer.png │ │ └── question.png │ ├── python │ │ └── main.py │ └── readme.md ├── 54-fibonacci-m-and-n │ ├── doc │ │ ├── answer.png │ │ ├── answer1.png │ │ └── question.png │ ├── python │ │ └── main.py │ └── readme.md ├── 55-reverse-number │ ├── doc │ │ ├── answer.png │ │ └── question.png │ ├── python │ │ └── main.py │ └── readme.md ├── 56-bin-to-8-10-16 │ ├── doc │ │ ├── answer.png │ │ └── question.png │ ├── python │ │ └── main.py │ └── readme.md ├── 57-long-long-numbers │ ├── doc │ │ ├── answer.png │ │ └── question.png │ ├── python │ │ └── main.py │ └── readme.md ├── 58-factiorial-value │ ├── doc │ │ ├── answer.png │ │ └── question.png │ ├── python │ │ └── main.py │ └── readme.md ├── 59-min-max-avg │ ├── doc │ │ ├── answer.png │ │ └── question.png │ ├── python │ │ └── main.py │ └── readme.md ├── 60-number-of-divisible │ ├── doc │ │ ├── answer.png │ │ └── question.png │ ├── python │ │ └── main.py │ └── readme.md ├── 61-union │ ├── doc │ │ ├── answer.png │ │ └── question.png │ ├── python │ │ └── main.py │ └── readme.md ├── 62-a-div-b and c-div-d │ ├── doc │ │ ├── answer.png │ │ └── question.png │ ├── python │ │ └── main.py │ └── readme.md ├── 63-find-x │ ├── doc │ │ ├── answer.png │ │ └── question.png │ ├── python │ │ └── main.py │ └── readme.md ├── 64-find-another-x │ ├── doc │ │ ├── answer.png │ │ └── question.png │ ├── python │ │ └── main.py │ └── readme.md ├── 65-1000-prime-number │ ├── doc │ │ └── question.png │ ├── python │ │ └── main.py │ └── readme.md ├── 66-median │ ├── doc │ │ ├── answer.png │ │ └── question.png │ ├── python │ │ └── main.py │ └── readme.md ├── 67-prime-2-n │ ├── Python │ │ └── main.py │ ├── README.md │ └── docs │ │ ├── answer.png │ │ └── question.jpg ├── 68-biggest-prime-2-n-into-n │ ├── Python │ │ └── main.py │ └── README.md ├── 69-Reverse-Numbers │ ├── C# │ │ └── Reverse-numbers.cs │ ├── Python │ │ └── app.py │ ├── README.md │ └── docs │ │ ├── answer.png │ │ └── question.jpg ├── 69-Reverse-String-input │ ├── Python │ │ └── app.py │ └── README.md ├── 70-Mult-Table │ ├── Python │ │ └── app.py │ ├── README.md │ └── doc │ │ └── question.png ├── 71-Pascals-triangle │ ├── Python │ │ └── app.py │ ├── README.md │ └── doc │ │ └── question.png ├── 72-level-2-equations │ ├── JavaScript │ │ ├── app.js │ │ └── index.html │ ├── Python │ │ └── app.py │ ├── README.md │ └── docs │ │ └── question.png ├── 73-distinct-numbers │ ├── Python │ │ └── app.py │ ├── README.md │ └── doc │ │ └── quiz.png ├── 74-JackSparo │ ├── Python │ │ └── app.py │ ├── README.md │ └── doc │ │ └── quiz.png ├── 75-Delta-Logo-D │ ├── Python │ │ └── app.py │ ├── README.md │ └── doc │ │ └── quiz.png ├── 76-sticks-length │ ├── Python │ │ └── app.py │ └── README.md ├── 77-song-length │ ├── Python │ │ └── app.py │ ├── README.md │ └── tests │ │ ├── 1.in │ │ ├── 1.out │ │ ├── 10.in │ │ ├── 10.out │ │ ├── 11.in │ │ ├── 11.out │ │ ├── 12.in │ │ ├── 12.out │ │ ├── 13.in │ │ ├── 13.out │ │ ├── 14.in │ │ ├── 14.out │ │ ├── 15.in │ │ ├── 15.out │ │ ├── 16.in │ │ ├── 16.out │ │ ├── 17.in │ │ ├── 17.out │ │ ├── 18.in │ │ ├── 18.out │ │ ├── 19.in │ │ ├── 19.out │ │ ├── 2.in │ │ ├── 2.out │ │ ├── 20.in │ │ ├── 20.out │ │ ├── 3.in │ │ ├── 3.out │ │ ├── 4.in │ │ ├── 4.out │ │ ├── 5.in │ │ ├── 5.out │ │ ├── 6.in │ │ ├── 6.out │ │ ├── 7.in │ │ ├── 7.out │ │ ├── 8.in │ │ ├── 8.out │ │ ├── 9.in │ │ └── 9.out ├── 78-DNA-Repetitions │ ├── Python │ │ └── app.py │ └── README.md ├── 79-safe-locker │ ├── Python │ │ └── app.py │ └── README.md ├── 80-valid-parentheses │ ├── Python │ │ └── app.py │ └── README.md └── 81-RGB-supplement │ ├── Python │ └── app.py │ ├── README.md │ └── doc │ └── quiz.png └── README.md /.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 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 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 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # poetry 98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 99 | # This is especially recommended for binary packages to ensure reproducibility, and is more 100 | # commonly ignored for libraries. 101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 102 | #poetry.lock 103 | 104 | # pdm 105 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 106 | #pdm.lock 107 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 108 | # in version control. 109 | # https://pdm.fming.dev/#use-with-ide 110 | .pdm.toml 111 | 112 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 113 | __pypackages__/ 114 | 115 | # Celery stuff 116 | celerybeat-schedule 117 | celerybeat.pid 118 | 119 | # SageMath parsed files 120 | *.sage.py 121 | 122 | # Environments 123 | .env 124 | .venv 125 | env/ 126 | venv/ 127 | ENV/ 128 | env.bak/ 129 | venv.bak/ 130 | 131 | # Spyder project settings 132 | .spyderproject 133 | .spyproject 134 | 135 | # Rope project settings 136 | .ropeproject 137 | 138 | # mkdocs documentation 139 | /site 140 | 141 | # mypy 142 | .mypy_cache/ 143 | .dmypy.json 144 | dmypy.json 145 | 146 | # Pyre type checker 147 | .pyre/ 148 | 149 | # pytype static type analyzer 150 | .pytype/ 151 | 152 | # Cython debug symbols 153 | cython_debug/ 154 | 155 | .idea 156 | # PyCharm 157 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 158 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 159 | # and can be added to the global gitignore or merged into this file. For a more nuclear 160 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 161 | #.idea/ -------------------------------------------------------------------------------- /Advanced-Questions/01-monty-hall-problem/Python/main.py/main.py: -------------------------------------------------------------------------------- 1 | import random 2 | print("Monty Hall Problem") 3 | 4 | def spotDoor(): 5 | #door1 6 | spotChosen = random.randint(0, 2) 7 | doors[0] = spots[spotChosen] 8 | spots.pop(spotChosen) 9 | #door2 10 | spotChosen = random.randint(0, 1) 11 | doors[1] = spots[spotChosen] 12 | spots.pop(spotChosen) 13 | #door3 14 | doors[2] = spots[0] 15 | spots.pop(0) 16 | 17 | 18 | def userFirstChoice(): 19 | print(doorsVisual) 20 | global selectedDoor 21 | #input-check 22 | while True: 23 | try: 24 | print("Which door would you like to open?") 25 | selectedDoor = int(input()) 26 | except: 27 | print("Please enter an integer between 1 and 3") 28 | continue 29 | if selectedDoor >= 1 and selectedDoor <= 3: 30 | break 31 | else: 32 | print("Please enter an integer between 1 and 3") 33 | continue 34 | selectedDoor -= 1 35 | #reveal the one of the goats 36 | 37 | 38 | def reveal(): 39 | global revealedDoor 40 | revealedDoor = random.randint(0, 2) 41 | while revealedDoor == selectedDoor or doors[revealedDoor] == "CAR": 42 | revealedDoor = random.randint(0, 2) 43 | global doorsVisual 44 | doorsVisual = doorsVisual.replace( 45 | ("| " + str(revealedDoor+1) + " |"), "| GOAT |") 46 | print(doorsVisual) 47 | print("There is a " + doors[revealedDoor] + 48 | " behind door number " + str(revealedDoor + 1)) 49 | print("Would you like to switch? (y/n)") 50 | global switch 51 | switch = str(input()) 52 | while switch != "y" and switch != "n": 53 | print("Please enter y for yes or n for no") 54 | switch = str(input()) 55 | if switch == "y": 56 | switch = True 57 | else: 58 | switch = False 59 | 60 | 61 | def switchingDoor(switch): 62 | if switch: 63 | global switchTo 64 | switchTo = random.randint(0, 2) 65 | while switchTo == revealedDoor or switchTo == selectedDoor: 66 | switchTo = random.randint(0, 2) 67 | print("There is a " + doors[switchTo] + 68 | " behind door number " + str(switchTo+1)) 69 | global doorsVisual 70 | if doors[switchTo] == "CAR": 71 | doorsVisual = doorsVisual.replace( 72 | ("| " + str(switchTo+1) + " |"), "| CAR |") 73 | doorsVisual = doorsVisual.replace( 74 | ("| " + str(selectedDoor+1) + " |"), "| GOAT |") 75 | print(doorsVisual) 76 | print('') 77 | print("You Won!") 78 | else: 79 | doorsVisual = doorsVisual.replace( 80 | ("| " + str(selectedDoor+1) + " |"), "| CAR |") 81 | doorsVisual = doorsVisual.replace( 82 | ("| " + str(switchTo+1) + " |"), "| GOAT |") 83 | print(doorsVisual) 84 | print('') 85 | print("You Lost!") 86 | 87 | #opens selected door while switching door == false 88 | 89 | 90 | def openingDoor(switch): 91 | if not switch: 92 | global notOpened 93 | notOpened = random.randint(0, 2) 94 | while notOpened == revealedDoor or notOpened == selectedDoor: 95 | notOpened = random.randint(0, 2) 96 | print("There is a " + doors[selectedDoor] + 97 | " behind door number " + str(notOpened+1)) 98 | global doorsVisual 99 | if doors[selectedDoor] == "CAR": 100 | doorsVisual = doorsVisual.replace( 101 | ("| " + str(selectedDoor+1) + " |"), "| CAR |") 102 | doorsVisual = doorsVisual.replace( 103 | ("| " + str(notOpened+1) + " |"), "| GOAT |") 104 | print(doorsVisual) 105 | print('') 106 | print("You Won!") 107 | else: 108 | doorsVisual = doorsVisual.replace( 109 | ("| " + str(notOpened+1) + " |"), "| CAR |") 110 | doorsVisual = doorsVisual.replace( 111 | ("| " + str(selectedDoor+1) + " |"), "| GOAT |") 112 | print(doorsVisual) 113 | print('') 114 | print("You Lost!") 115 | 116 | 117 | #Game Loop 118 | while True: 119 | #global vars 120 | spots = ["GOAT", "GOAT", "CAR"] 121 | doors = ["door1", "door2", "door3"] 122 | doorsVisual = """ 123 | |-----------| |-----------| |-----------| 124 | | | | | | | 125 | | | | | | | 126 | | 1 | | 2 | | 3 | 127 | | | | | | | 128 | | | | | | | 129 | |-----------| |-----------| |-----------| 130 | """ 131 | 132 | spotDoor() 133 | userFirstChoice() 134 | reveal() 135 | switchingDoor(switch) 136 | openingDoor(switch) 137 | print("Would you like to play again? (y/n)") 138 | again = input() 139 | while again != "y" and again != "n": 140 | print("Please enter y for yes and n for no") 141 | again = input() 142 | if again == "y": 143 | continue 144 | else: 145 | print("Thanks") 146 | break 147 | -------------------------------------------------------------------------------- /Advanced-Questions/01-monty-hall-problem/README.md: -------------------------------------------------------------------------------- 1 | # Monty Hall problem :door: 2 | **Monty's Here! Monty knows everything. :ghost:**\ 3 | Monty Hall problem is a probability puzzle in which you challenge yourself to find the car. :car: 4 | 5 | ## Game Direction 6 | Monty is the game host. He knows everything. He asks you to choose one of the three doors. 7 | Behind two of them, there are two goats but behind one of them, there is your fancy prize which is a car.\ 8 | \ 9 | After you make your first selection, Monty tells you where one of the goats is located. Then he offers you to switch to the other door. You can either stick to your first selection or switch. 10 | \ 11 | Whether you stick to your selection, Monty will open the two other doors. If a goat is behind your door, you lose, otherwise, the car is yours! 💯 💯 💯 12 | \ 13 | \ 14 | ![Monty Hall problem](https://upload.wikimedia.org/wikipedia/commons/thumb/3/3f/Monty_open_door.svg/1200px-Monty_open_door.svg.png) 15 | ### Game Tip! 16 | It is recommended always to switch as there is a higher probability for the car to be behind the door you have not chosen. To understand the probabilities in this game watch [this video on YouTube](https://youtu.be/4Lb-6rxZxx0). 17 | 18 | added by: https://github.com/sprshr 19 | -------------------------------------------------------------------------------- /Advanced-Questions/02-call-center/Python/main.py: -------------------------------------------------------------------------------- 1 | import os, sys 2 | try: 3 | from tabulate import tabulate 4 | except ImportError: 5 | raise ImportError("tabulate lib is not installed!\n install it with:\n\tpip install tabulate") 6 | 7 | 8 | # each pules => 46 9 | # 4% tax for all call's 10 | # 23-8 am 50% 11 | # day 7 call is 75% off 12 | 13 | def get_time(m): 14 | """ 15 | this function get time by defination role 16 | 0 - 23 17 | """ 18 | while True: 19 | x = input(m) 20 | try: 21 | x = int(x) 22 | # for getting vlaid time 23 | if 0 <= x <= 23: 24 | pass 25 | else: 26 | continue 27 | except ValueError: 28 | continue 29 | else: 30 | return x 31 | 32 | 33 | def get_int(m): 34 | """ this function only accept numbers ! """ 35 | while True: 36 | x = input(m) 37 | try: 38 | x = int(x) 39 | except ValueError: 40 | continue 41 | else: 42 | return x 43 | 44 | 45 | def get_day(m): 46 | """ this function only accept number that between 0 -7 day of the week """ 47 | while True: 48 | x = input(m) 49 | try: 50 | x = int(x) 51 | 52 | if 0 <= x <= 7: 53 | return x 54 | else: 55 | continue 56 | 57 | except ValueError: 58 | continue 59 | else: 60 | return x 61 | 62 | 63 | def gete_users(): 64 | """ this function take users and replace them in structure like json response """ 65 | x = input("Enter Number Of Users: ") 66 | try: 67 | x = int(x) 68 | except ValueError: 69 | sys.exit("Invalid input :( ") 70 | 71 | users = [] 72 | for i in range(x): 73 | temp = {} 74 | temp["user"] = i + 1 75 | temp["time"] = get_time(f"Enter Start Time of Call for User-{i + 1}: ") 76 | temp["pules"] = get_int(f"Enter Number of Pules for User-{i + 1}: ") 77 | temp["day"] = get_day(f"Enter Day of that User-{i + 1} Call: ") 78 | temp["price"] = 0 79 | users.append(temp) 80 | 81 | return users 82 | 83 | 84 | 85 | def calculate_price(users): 86 | """ this function calculate price of each call """ 87 | for each in users: 88 | # check time and date 89 | each["price"] = (each["pules"] * 46) 90 | 91 | if each["time"] == 7: 92 | # 75 off 93 | each["price"] = each["price"] - (75 * (each["pules"] / 100)) 94 | 95 | # check time fo 23 to 8 96 | if 0 <= each["time"] <= 8: 97 | each["price"] = each["price"] - (50 * each["price"] / 100 ) 98 | 99 | # calculate tax -> 4 % 100 | each["price"] = each["price"] + (4 * each["price"] / 100) 101 | 102 | return users 103 | 104 | 105 | def main(): 106 | users = gete_users() 107 | prices = calculate_price(users) 108 | users = [ [each["user"] , each["time"] , each["pules"], each["day"], each["price"] ] for each in users] 109 | print(tabulate(users,headers=["user","time", "pules", "day", "price"], tablefmt="github")) 110 | 111 | 112 | if __name__ == "__main__": 113 | main() 114 | -------------------------------------------------------------------------------- /Advanced-Questions/02-call-center/README.md: -------------------------------------------------------------------------------- 1 | # کارشناسی نرم افزار روزانه یزد 2 | مبانی بازیابی اطلاعات و جستجوی وب 3 | 4 | سوال: 5 | 6 | 7 | 8 | 9 | خروجی: 10 | 11 | 12 | -------------------------------------------------------------------------------- /Advanced-Questions/02-call-center/docs/answer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Advanced-Questions/02-call-center/docs/answer.png -------------------------------------------------------------------------------- /Advanced-Questions/02-call-center/docs/question.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Advanced-Questions/02-call-center/docs/question.png -------------------------------------------------------------------------------- /Advanced-Questions/03-hash-cracker/Python/main.py: -------------------------------------------------------------------------------- 1 | import csv 2 | import hashlib 3 | 4 | 5 | 6 | def hash_data(filename): 7 | with open(filename, 'r') as f: 8 | reader = csv.reader(f) 9 | reader.__next__() 10 | data = {} 11 | for row in reader: 12 | data[row[1].strip()] = 0 13 | 14 | return data 15 | 16 | 17 | def main(): 18 | filename = "../passwords.csv" 19 | hash_data_dict = hash_data(filename) 20 | 21 | counter = 0 22 | let_data = len(hash_data_dict.items()) 23 | 24 | for each in range(1, (99_999+1)): 25 | if let_data == counter: 26 | break 27 | 28 | hash = hashlib.md5(str(each).encode("UTF-8")).hexdigest() 29 | 30 | if hash in hash_data_dict: 31 | hash_data_dict[hash] = each 32 | counter += 1 33 | 34 | print("----" * 21, end="\n") 35 | for each in hash_data_dict: 36 | print(f"the orginal password for hash value \033[31m <{each}> \033[0m is \033[33m {hash_data_dict[each]} \033[0m") 37 | print("----" * 21, end="\n") 38 | 39 | 40 | if __name__ == "__main__": 41 | main() -------------------------------------------------------------------------------- /Advanced-Questions/03-hash-cracker/passwords.csv: -------------------------------------------------------------------------------- 1 | name, pass, created_time 2 | ali, 3dba880b99f7157c9f362be445a56493, 2023-10-21 3 | mina, af070abdf5156acd363fca2b6f391ace, 2023-2-21 4 | reza, 6483a599028c6f20aa6f40c3b507420d, 2023-5-21 5 | nahid, e1f979ea2b94f4a754835ee9f85cf0d0, 2023-11-21 6 | hassan, 348dc21a8acf9658140e0536eb14783d, 2023-1-21 7 | John Duo, e57023ed682d83a41d25acb650c877da, 2020-20-20 8 | -------------------------------------------------------------------------------- /Advanced-Questions/03-hash-cracker/readme.md: -------------------------------------------------------------------------------- 1 | # brute force md5 2 | 3 | علی یک پژوهشگر امنیتی است، او به تارگی توانسته دیتابیس یک سایت را بدست بیاورد اما مقادیر با الگوریتم md5 رمزنگاری شده اند به علی برای حل این مشکل کمک کنید 4 | 5 | -- 6 | علی میداند که تمامی گذرواژه ها در سایت باید بین 1 تا 99999 انتخاب شود 7 | علی می داند که پسورد ها با الگوریتم md5 رمزنگاری شده اند 8 | علی میداند که برای ساخت یه md5 در پایتون باید از لایبری hashlib استفاده کند -------------------------------------------------------------------------------- /Advanced-Questions/04-binary-search/Python/app.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | 4 | global steps 5 | steps:int = 0 6 | 7 | print("[G] Generating List ") 8 | test_arr:list = [x for x in range(1,1_00_000_000+1)] 9 | print("[EG] List generated successfully") 10 | 11 | 12 | def bin_search(arr:list, tar:int, end:int, start:int=0): 13 | """ 14 | arr = array for search 15 | tar = target number for search 16 | start = location for the start 17 | end = end location of search 18 | """ 19 | global steps 20 | # print(f"start: {start}, end:{end}") 21 | for each in range(start, end): 22 | middle = (start+end)//2 23 | if arr[middle] > tar: 24 | steps += 1 25 | return bin_search(arr=arr, tar=tar, start=start, end=middle) 26 | elif arr[middle] < tar: 27 | steps += 1 28 | return bin_search(arr=arr, tar=tar, start=middle, end=end) 29 | else: 30 | return [f"Found :{arr[middle]} Using Binary algorithm, in {steps} steps", time.time() * 1000] 31 | 32 | 33 | def linear_search(arr, tar): 34 | start = time.time() * 1000 35 | for index, value in enumerate(arr): 36 | if value == tar: 37 | end=(time.time() * 1000) 38 | return f"Found {value} Using linear algorithm, in {index+1} steps, {end - start} ms" 39 | 40 | 41 | 42 | 43 | print(f"[S] Search Started!") 44 | start = time.time() * 1000 45 | result = bin_search(arr=test_arr, tar=9_9999_999, start=0, end=len(test_arr)) 46 | print(result[0], f"in {result[-1] - start} ms") 47 | 48 | 49 | result = linear_search(arr=test_arr, tar=9_9999_999) 50 | print(result) 51 | -------------------------------------------------------------------------------- /Advanced-Questions/04-binary-search/README.md: -------------------------------------------------------------------------------- 1 | # جستجوی دودویی - باینری 2 | 3 | 4 | محمد یک لیست مرتب شده از اعداد بین 1 تا 10 میلیون دارد و میخواهد دنبال عدد 9,999,999 در لیست اعداد بگردد 5 | برنامه ای بنویسید که در این لیست با استفاده از الگوریتم باینری دنبال عدد مورد نظر بگردد و تایم جستجو رو نمایش دهد -------------------------------------------------------------------------------- /Advanced-Questions/05-merge-sorted-array/README.md: -------------------------------------------------------------------------------- 1 | Merge Sorted Array 2 | Hint 3 | You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2 respectively. 4 | 5 | Merge nums1 and nums2 into a single array sorted in non-decreasing order. 6 | 7 | The final sorted array should not be returned by the function, but instead be stored inside the array nums1. To accommodate this, nums1 has a length of m + n, where the first m elements denote the elements that should be merged, and the last n elements are set to 0 and should be ignored. nums2 has a length of n. 8 | 9 | 10 | 11 | Example 1: 12 | 13 | Input: nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3 14 | Output: [1,2,2,3,5,6] 15 | Explanation: The arrays we are merging are [1,2,3] and [2,5,6]. 16 | The result of the merge is [1,2,2,3,5,6] with the underlined elements coming from nums1. 17 | Example 2: 18 | 19 | Input: nums1 = [1], m = 1, nums2 = [], n = 0 20 | Output: [1] 21 | Explanation: The arrays we are merging are [1] and []. 22 | The result of the merge is [1]. 23 | Example 3: 24 | 25 | Input: nums1 = [0], m = 0, nums2 = [1], n = 1 26 | Output: [1] 27 | Explanation: The arrays we are merging are [] and [1]. 28 | The result of the merge is [1]. 29 | Note that because m = 0, there are no elements in nums1. The 0 is only there to ensure the merge result can fit in nums1. 30 | 31 | 32 | Constraints: 33 | 34 | nums1.length == m + n 35 | nums2.length == n 36 | 0 <= m, n <= 200 37 | 1 <= m + n <= 200 38 | -109 <= nums1[i], nums2[j] <= 109 39 | 40 | 41 | Follow up: Can you come up with an algorithm that runs in O(m + n) time? -------------------------------------------------------------------------------- /Medium-Questions/01-even-Or-odd-(Fa)/C#/One.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace ConsoleApplication1 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | 14 | // get input from user 15 | Console.WriteLine("Enter a Number: "); 16 | string user = Console.ReadLine(); 17 | 18 | // Convert input to int 19 | int int_user= Int32.Parse(user); 20 | // check to input between 1 to 100 21 | if (int_user < 100 && int_user > 0) 22 | { 23 | // check for Even or odd Number 24 | if (int_user % 2 == 0) 25 | { 26 | Console.WriteLine("Even Number"); 27 | } 28 | else 29 | { 30 | Console.WriteLine("Odd Number"); 31 | } 32 | 33 | } 34 | else 35 | { 36 | // if Number is not between 1 to 100 37 | Console.WriteLine("Its Not betweeb 1 to 100"); 38 | } 39 | Console.ReadKey(); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Medium-Questions/01-even-Or-odd-(Fa)/C/one.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | 6 | int user; 7 | // get input from user 8 | printf("Enter a Number: "); 9 | scanf("%i", &user); 10 | 11 | // check for number between 1 to 100 12 | if (user > 0 && user < 100) 13 | { 14 | // check for Number is even or odd 15 | if (user % 2 == 0) 16 | { 17 | printf("Even Number :) "); 18 | return 0; 19 | } 20 | else 21 | { 22 | printf("Odd Number :) "); 23 | return 0; 24 | } 25 | } 26 | // if number is out of Range 27 | else 28 | { 29 | printf("Invalid Number - Number must Between 1 to 100"); 30 | return 1; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Medium-Questions/01-even-Or-odd-(Fa)/Lua/one.lua: -------------------------------------------------------------------------------- 1 | local number = io.read("n") 2 | 3 | if (number > 100 or number < 0) then 4 | print("Invalid number") 5 | os.exit(1) 6 | end 7 | if (number % 2 == 0) then 8 | print("even number") 9 | elseif (number % 2 == 1) then 10 | print("odd number") 11 | end 12 | -------------------------------------------------------------------------------- /Medium-Questions/01-even-Or-odd-(Fa)/Node/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node", 3 | "version": "1.0.0", 4 | "main": "src/one.js", 5 | "dependencies": {}, 6 | "devDependencies": { 7 | "chai": "^4.3.6", 8 | "mocha": "^10.0.0" 9 | }, 10 | "scripts": { 11 | "test": "mocha" 12 | }, 13 | "keywords": [], 14 | "author": "", 15 | "license": "ISC", 16 | "description": "" 17 | } 18 | -------------------------------------------------------------------------------- /Medium-Questions/01-even-Or-odd-(Fa)/Node/src/one.js: -------------------------------------------------------------------------------- 1 | const readLine = require("readline").createInterface({ 2 | input: process.stdin, 3 | output: process.stdout, 4 | }); 5 | 6 | readLine.question("Inter the number: ", validation); 7 | 8 | function validation(number) { 9 | //String to Number 10 | const num = Number(number); 11 | 12 | let state = "not valid - Odd Number"; 13 | 14 | if (num >= 100 || num < 1) { 15 | state = "Invalid Number - Number must Between 1 to 100"; 16 | } else if (num % 2 === 0) { 17 | state = "valid - Even Number"; 18 | } 19 | 20 | readLine.close(); 21 | console.log(state); 22 | return state; 23 | } 24 | 25 | module.exports = validation; 26 | -------------------------------------------------------------------------------- /Medium-Questions/01-even-Or-odd-(Fa)/Php/One.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 | 11 | 100 && $number < 0) 16 | { 17 | exit("Number not between1 to 100"); 18 | } 19 | if ($number % 2 == 0) 20 | { 21 | echo("

Even Number

"); 22 | } 23 | else 24 | { 25 | echo("

Not a Even Number

"); 26 | } 27 | } 28 | 29 | 30 | ?> 31 | 32 |
33 | 34 | 35 |
36 | 37 | 38 | -------------------------------------------------------------------------------- /Medium-Questions/01-even-Or-odd-(Fa)/README.md: -------------------------------------------------------------------------------- 1 | - برنامه ای بنویسید که با پیامی مناسب عددی را دریافت کرده و در صورتی که عدد زوج باشد و در بازه ۱ 2 | تا ۱00 قرار داشته باشد پیغام “.Valid “و در غیر این صورت پیام “!Valid Not “را نمایش دهد. 3 | 4 | ## مبانی برنامه سازی - پایتون 5 | نیمسال دوم 98-97 6 | هادیان - دانشگاه شریف 7 | 8 | > مثال: 9 | >> ورودی : 2 10 | >>
11 | >> خروجی : 'True' or 'Even Number' or '0' or 'valid' 12 | >>
13 | >>
14 | >> ورودی : 3 15 | >>
16 | >> خروجی: 'False' or 'Odd Number' or '1' or 'not valid' 17 | 18 | 19 | 20 | ------------- 21 | - Write a program that asks the user for a number 22 | And then print to the user that number is a even or odd Number 23 | 24 | > example: 25 | >> input : 2 26 | >>
27 | >> output: 'True' or 'Even Number' or '0' or 'valid' 28 | >>
29 | >>
30 | >> input : 3 31 | >>
32 | >> output: 'False' or 'Odd Number' or '1' or 'not valid' 33 | 34 | 35 | https://github.com/alisharifyy/Programming-Questions 36 | -------------------------------------------------------------------------------- /Medium-Questions/01-even-Or-odd-(Fa)/python/One.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | # defind a function for decied a Number 4 | # is Even or odd 5 | 6 | def is_valid(number): 7 | """ this Function take one Argument and if Number is Even Return true 8 | otherwise Return False""" 9 | if (number % 2 == 0): 10 | return True 11 | return False 12 | 13 | # get input from user 14 | input_user = int(input("Enter Number: ")) 15 | 16 | # check for numbre between 1 to 100 17 | if (input_user > 0 and input_user <= 100): 18 | 19 | # pass number to is_valid function for checking 20 | if (is_valid(input_user)): 21 | print("Even Number (valid)") 22 | sys.exit(0) 23 | else: 24 | print("Odd Number (Not valid)") 25 | sys.exit(0) 26 | else: 27 | print("input out of Range 1 to 100") 28 | 29 | 30 | sys.exit(0) 31 | -------------------------------------------------------------------------------- /Medium-Questions/01-even-Or-odd-(Fa)/rust/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "rust" 7 | version = "0.1.0" 8 | -------------------------------------------------------------------------------- /Medium-Questions/01-even-Or-odd-(Fa)/rust/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rust" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | -------------------------------------------------------------------------------- /Medium-Questions/01-even-Or-odd-(Fa)/rust/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::io; 2 | fn main() { 3 | let mut input = String::new(); 4 | println!("Enter your number: "); 5 | 6 | io::stdin().read_line(&mut input).expect("Try Again!"); 7 | 8 | let input: u32 = input.trim().parse().expect("Enter an number between 1-100: "); 9 | 10 | let res:&'static str = validtion_number(input); 11 | 12 | println!("{}",res); 13 | 14 | } 15 | 16 | 17 | fn validtion_number(input:u32) -> &'static str { 18 | if input >= 100 || input == 0{ 19 | return "Invalid Number - Number must Between 1 to 100"; 20 | } 21 | 22 | if input%2==0 { 23 | "Even Number" 24 | } else { 25 | "Odd Number" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Medium-Questions/02-Star-Number-(Fa)/C#/Two.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Two 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | // get input from user 14 | Console.Write("Enter a Number: "); 15 | string user = Console.ReadLine(); 16 | 17 | // convert int to string 18 | int res = Int32.Parse(user); 19 | 20 | // this for loop is for row 21 | for (int i = 1; i <= res; i++) 22 | { 23 | // this for loop is for print Star 24 | for (int j = 0; j < i; j++) 25 | { 26 | Console.Write("*"); 27 | } 28 | // print New Line 29 | Console.WriteLine(""); 30 | } 31 | 32 | Console.ReadKey(); 33 | } 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Medium-Questions/02-Star-Number-(Fa)/C/Two.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | int main(void) 5 | { 6 | // Get input from user 7 | int user = 0; 8 | printf("Enter a Number: "); 9 | scanf("%i", &user); 10 | 11 | if (user < 1) 12 | { 13 | printf("Invalid input :(") 14 | return 1; 15 | } 16 | 17 | // this for loop is for Row 18 | for (int i = 1; i <= user ;i++) 19 | { 20 | for (int j = 0; j < i ; j++) 21 | { 22 | printf("*"); 23 | } 24 | // Print New Line in end of each Row 25 | printf("\n"); 26 | 27 | } 28 | return 0; 29 | } -------------------------------------------------------------------------------- /Medium-Questions/02-Star-Number-(Fa)/Lua/two.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/02-Star-Number-(Fa)/Lua/two.lua -------------------------------------------------------------------------------- /Medium-Questions/02-Star-Number-(Fa)/Node/Two.js: -------------------------------------------------------------------------------- 1 | const readline = require('readline').createInterface({ 2 | input: process.stdin, 3 | output: process.stdout 4 | }); 5 | 6 | readline.question('Enter a Number:', number => { 7 | for(let i = 1; i <= number;i++) 8 | { 9 | for (let j = 0; j 12 | 13 | > input: 3 14 | 15 |
16 | 17 | > output: 18 | 19 |
20 | * \n 21 |
22 | ** \n 23 |
24 | *** \n 25 | 26 | 27 | https://github.com/alisharifyy/Programming-Questions -------------------------------------------------------------------------------- /Medium-Questions/03-Binary-Star-(Fa)/C#/Three-1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace ThreeOOO 8 | { 9 | class Program 10 | { 11 | 12 | // deifnd a function that take a Number 13 | // and return number on One In that Number in binary\ 14 | 15 | static int bin_num(int number) { 16 | 17 | int counter = 0; 18 | 19 | // convert int number to Binary number 20 | string binary = Convert.ToString(number, 2); 21 | 22 | // iterate over all string 23 | foreach (char one in binary) 24 | { 25 | // if i element is string equal to 1 26 | if(one == '1') 27 | { 28 | counter++; 29 | } 30 | } 31 | 32 | // return Number of One in binaary 33 | return counter; 34 | 35 | } 36 | 37 | static void Main(string[] args) 38 | { 39 | // Get input From User 40 | Console.Write("Enter a Number: "); 41 | string user = Console.ReadLine(); 42 | // Convert string Input to Int 43 | int user_in = Int32.Parse(user); 44 | 45 | // Send Int value To bin_num Function to 46 | // Return Number of 1 in it 47 | int answer = bin_num(user_in); 48 | 49 | // print result 50 | Console.WriteLine(answer); 51 | 52 | 53 | Console.ReadKey(); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Medium-Questions/03-Binary-Star-(Fa)/C#/Three-2.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace ThreeOO 8 | { 9 | class Program 10 | { 11 | 12 | // this function take a number and 13 | // print star 14 | static void print_star(int number) 15 | { 16 | // safety check 17 | if (number < 0) 18 | { 19 | Console.Write("Error"); 20 | } 21 | 22 | // This for loop is for Row 23 | for (int i = 1; i <= number; i++) 24 | { 25 | // this for loop is for print Star 26 | for (int j = 0; j < i; j++) 27 | { 28 | Console.Write("*"); 29 | } 30 | // Print New Line 31 | Console.WriteLine(""); 32 | } 33 | 34 | } 35 | 36 | 37 | static void Main(string[] args) 38 | { 39 | 40 | // Test the Function 41 | print_star(15); 42 | 43 | 44 | Console.ReadKey(); 45 | } 46 | 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Medium-Questions/03-Binary-Star-(Fa)/C#/Three-3.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace threeO 8 | { 9 | class Program 10 | { 11 | // this function take a number and Print Star With it 12 | static void print_star(int number) 13 | { 14 | // safety check 15 | if (number < 0) 16 | { 17 | Console.Write("Error"); 18 | } 19 | 20 | // This for loop is for Row 21 | for (int i = 1; i <= number; i++) 22 | { 23 | // this for loop is for print Star 24 | for (int j = 0; j < i; j++) 25 | { 26 | Console.Write("*"); 27 | } 28 | // Print New Line 29 | Console.WriteLine(""); 30 | } 31 | 32 | } 33 | 34 | 35 | // This function take A number and return number of 1 in Binary 36 | static int bin_num(int number) 37 | { 38 | 39 | int counter = 0; 40 | 41 | // convert int number to Binary number 42 | string binary = Convert.ToString(number, 2); 43 | 44 | // iterate over all string 45 | foreach (char one in binary) 46 | { 47 | // if i element is string equal to 1 48 | if (one == '1') 49 | { 50 | counter++; 51 | } 52 | } 53 | 54 | // return Number of One in binaary 55 | return counter; 56 | 57 | } 58 | 59 | static void Main(string[] args) 60 | { 61 | // get input from user 62 | Console.Write("Enter a Number: "); 63 | string user = Console.ReadLine(); 64 | // convert string to int 65 | int temp = Int32.Parse(user); 66 | 67 | // get number of 1 in user input 68 | int bin_number = bin_num(temp); 69 | 70 | // print star 71 | print_star(bin_number); 72 | 73 | 74 | Console.ReadKey(); 75 | 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /Medium-Questions/03-Binary-Star-(Fa)/JavaScript/Three.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 |

answer is here5

11 | 12 | 13 | https://github.com/alisharifyy/Programming-Questions 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Medium-Questions/03-Binary-Star-(Fa)/JavaScript/Three.js: -------------------------------------------------------------------------------- 1 | function dec2bin(dec) { 2 | return (dec >>> 0).toString(2); 3 | } 4 | 5 | function find1(number){ 6 | let counter = 0; 7 | for(let each of number) 8 | { 9 | if (each == "1") 10 | { 11 | counter++; 12 | } 13 | } 14 | return counter; 15 | } 16 | 17 | function Start_printer(number) 18 | { 19 | let answer = ""; 20 | for (let i = 1; i <= number; i++) 21 | { 22 | for (let j = 0; j < i; j++){ 23 | answer += " # "; 24 | } 25 | answer += "
"; 26 | } 27 | return answer; 28 | } 29 | 30 | let number = prompt("Number: "); 31 | let BinNumber = dec2bin(number); 32 | let oneNumber = find1(BinNumber); 33 | let answer = Start_printer(oneNumber); 34 | 35 | document.getElementById('answer').innerHTML = answer; -------------------------------------------------------------------------------- /Medium-Questions/03-Binary-Star-(Fa)/Python/three-1.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | def bin_digit(number): 4 | """first conver a int to binary then return number of one in binary Value""" 5 | counter = 0 6 | number = bin(number) 7 | length = len(number) 8 | 9 | for one in range(length): 10 | if (number[one] == '1'): 11 | counter += 1 12 | 13 | return counter 14 | 15 | try: 16 | user = int(input("user: ")) 17 | except ValueError: 18 | print("its not a number") 19 | sys.exit(1) 20 | 21 | 22 | print(bin_digit(user)) 23 | sys.exit(0) 24 | -------------------------------------------------------------------------------- /Medium-Questions/03-Binary-Star-(Fa)/Python/three-2.py: -------------------------------------------------------------------------------- 1 | 2 | import sys 3 | 4 | user_input = int(input("Enter a number: ")) 5 | if user_input <= 0: 6 | print("Negetive number !\n") 7 | sys.exit(1) 8 | else: 9 | for i in range(user_input): 10 | print("*") 11 | 12 | sys.exit(0) -------------------------------------------------------------------------------- /Medium-Questions/03-Binary-Star-(Fa)/Python/three-3.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | def bin_digit(number): 4 | """first conver a int to binary then return number of one in binary Value""" 5 | counter = 0 6 | number = bin(number) 7 | length = len(number) 8 | 9 | for one in range(length): 10 | if (number[one] == '1'): 11 | counter += 1 12 | 13 | return counter 14 | 15 | try: 16 | user = int(input("user: ")) 17 | except ValueError: 18 | print("its not a number") 19 | sys.exit(1) 20 | 21 | bin_number = bin_digit(user) 22 | 23 | for i in range(bin_number): 24 | print("*") 25 | 26 | 27 | sys.exit(0) -------------------------------------------------------------------------------- /Medium-Questions/03-Binary-Star-(Fa)/README.md: -------------------------------------------------------------------------------- 1 | # .توابع زیر را بنویسید : 2 | 3 | **تابع 1 : با دریافت یک عدد صحیح تعداد ارقام 1 آن عدد در نمایش مبنای دو را برگرداند.** 4 |
5 | **تابع 2 : با دریافت یک عدد صحیح به تعداد همان عدد ستاره * جاپ کند.** 6 |
7 | 8 | **حال به کمک توابع باال برنامه ای بنویسید که با دریافت یک عدد از کاربر به تعداد رقم های 1 آن عدد در نمایش مبنای 2 ستاره * چاپ کند.** 9 | 10 |
11 | 12 | 13 | # مبانی برنامه سازی - پایتون 14 | نیمسال دوم 98-97 15 | هادیان 16 | 17 | 18 | https://github.com/alisharifyy/Programming-Questions -------------------------------------------------------------------------------- /Medium-Questions/04-Bubble-Sort-(Fa)/C#/four.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace bubble 8 | { 9 | class Program 10 | { 11 | 12 | //this function print a array 13 | static void out_arr(int[] array_input) 14 | { 15 | 16 | for (int i =0; i < (array_input.Length - 1); i++) 17 | { 18 | Console.Write(array_input[i] + " "); 19 | } 20 | Console.WriteLine(" \n - - - \n "); 21 | 22 | } 23 | 24 | 25 | static void Main(string[] args) 26 | { 27 | int[] array = {10,9,8,7,6,5,4,3,2,1}; 28 | 29 | //10 * 10 option 30 | for (int i = 0; i < (array.Length - 1); i++) 31 | { 32 | for (int j = 0; j < (array.Length - 1); j++) 33 | { 34 | //print each time array 35 | out_arr(array); 36 | 37 | if (j + 1 > (array.Length - 1)) 38 | { 39 | continue; 40 | } 41 | 42 | int temp = array[j]; 43 | if (temp > array[j + 1]) 44 | { 45 | //swap values 46 | array[j] = array[j + 1]; 47 | array[j + 1] = temp; 48 | } 49 | 50 | } 51 | } 52 | Console.ReadKey(); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Medium-Questions/04-Bubble-Sort-(Fa)/Javascript/Four.js: -------------------------------------------------------------------------------- 1 | let numbers = [10,9,8,7,6,5,4,3,2,1]; 2 | for (let i = 0; i < numbers.length; i++) 3 | { 4 | for (let j = 0; j < (numbers.length); j++) 5 | { 6 | let temp = numbers[j]; 7 | if (temp > numbers[j+1]) 8 | { 9 | let temp1 = numbers[j+1]; 10 | numbers[j+1] = temp; 11 | numbers[j] = temp1; 12 | console.log(numbers); 13 | } 14 | else 15 | { 16 | continue; 17 | } 18 | 19 | } 20 | } -------------------------------------------------------------------------------- /Medium-Questions/04-Bubble-Sort-(Fa)/Javascript/four.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 |

answer is here5

11 | 12 | 13 | https://github.com/alisharifyy/Programming-Questions 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Medium-Questions/04-Bubble-Sort-(Fa)/Python/Four.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | 4 | # linear function 5 | def linear_sort(list_tmp): 6 | """this function take a list and sort all of element in it, and return sorted list""" 7 | flag = 0 8 | lenght =len(list_tmp) 9 | 10 | while (flag <= lenght * lenght): 11 | for i in range(len(list_tmp) - 1): 12 | if (list_tmp[i] > list_tmp[i + 1]): 13 | tmp = list_tmp[i] 14 | list_tmp[i] = list_tmp[i + 1] 15 | list_tmp[i + 1] = tmp 16 | flag += 1 17 | return list_tmp 18 | 19 | 20 | # unsorted lis with numbers 21 | numbers = [102,1567,234,123,4,21,3,567,213,56,8,5] 22 | final = linear_sort(numbers) 23 | print(final) 24 | 25 | sys.exit(0) -------------------------------------------------------------------------------- /Medium-Questions/04-Bubble-Sort-(Fa)/README.md: -------------------------------------------------------------------------------- 1 | 2 | ![description](img/4.png) 3 | 4 |
5 | # مبانی برنامه سازی - پایتون 6 | نیمسال دوم 98-97 7 | هادیان دانشگاه شریف 8 | 9 | 10 | https://github.com/alisharifyy/Programming-Questions 11 | -------------------------------------------------------------------------------- /Medium-Questions/04-Bubble-Sort-(Fa)/img/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/04-Bubble-Sort-(Fa)/img/4.png -------------------------------------------------------------------------------- /Medium-Questions/05-algorithm-odd/C#/Five.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Five 8 | { 9 | class Program 10 | { 11 | 12 | // this Function Return True if number is True 13 | // otherwise Return False 14 | 15 | static bool Even_odd(int number) 16 | { 17 | if (number % 2 == 0) 18 | { 19 | return true; 20 | } 21 | return false; 22 | 23 | 24 | } 25 | 26 | static void Main(string[] args) 27 | { 28 | // Get input From user 29 | Console.Write("Enter a Number: "); 30 | string user = Console.ReadLine(); 31 | 32 | // convert string to int 33 | int user_in = Int32.Parse(user); 34 | 35 | 36 | while (true) 37 | { 38 | // If n is 1 break 39 | if (user_in == 1) 40 | { 41 | Console.WriteLine("user is {0} ", user_in); 42 | break; 43 | 44 | } 45 | // if user input is Even divided by 2 46 | if (Even_odd(user_in) == true) 47 | { 48 | Console.WriteLine("user is {0}", user_in); 49 | user_in = user_in / 2; 50 | continue; 51 | } 52 | // if user input is odd 53 | // multiplies it by 3 54 | if (Even_odd(user_in) == false) 55 | { 56 | Console.WriteLine("user is {0}", user_in); 57 | user_in = user_in * 3; 58 | user_in++; 59 | continue; 60 | } 61 | 62 | } 63 | 64 | Console.ReadKey(); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Medium-Questions/05-algorithm-odd/C/five.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // this function decides input number is 5 | // even or odd 6 | bool even_odd(int number) 7 | { 8 | if (number % 2 == 0) 9 | { 10 | return true; 11 | } 12 | return false; 13 | } 14 | 15 | 16 | int main(void) 17 | { 18 | // get input from user 19 | int user; 20 | printf("Enter a number: "); 21 | scanf("%d", &user); 22 | 23 | while (true) 24 | { 25 | // if number is one break 26 | if (user == 1) 27 | { 28 | printf("Number is %i \n", user); 29 | break; 30 | } 31 | 32 | // if number is even 33 | // divided by 2 34 | if (even_odd(user) == true) 35 | { 36 | printf("Number is %i \n",user); 37 | user = user / 2; 38 | continue; 39 | } 40 | 41 | // if number is odd 42 | // multiplied by 3 and add one 43 | if (even_odd(user) == false) 44 | { 45 | printf("Number is %i \n",user); 46 | user = (user * 3) + 1; 47 | continue; 48 | } 49 | } 50 | return 0; 51 | } -------------------------------------------------------------------------------- /Medium-Questions/05-algorithm-odd/JavaScript/app.js: -------------------------------------------------------------------------------- 1 | // this function Specifies is a number even or odd 2 | function even(number) 3 | { 4 | if (number % 2 == 0) 5 | { 6 | return true; 7 | } 8 | else 9 | { 10 | return false; 11 | } 12 | } 13 | 14 | let answer = document.getElementById("answer"); 15 | let user = prompt("Enter a Number: "); 16 | console.log(user); 17 | 18 | 19 | while(true) 20 | { 21 | if (user < 0) 22 | { 23 | answer.innerHTML = "Number is one DOne"; 24 | break; 25 | } 26 | 27 | if (user == 1) 28 | { 29 | answer.innerHTML += "
" + "User input is One"; 30 | console.log("User input is One"); 31 | break; 32 | } 33 | 34 | else if(even(user)) 35 | { 36 | user = user / 2; 37 | answer.innerHTML += `
${user}` ; 38 | console.log(user); 39 | } 40 | 41 | else 42 | { 43 | user = (user * 3) + 1; 44 | answer.innerHTML += `
${user}` ; 45 | console.log(user); 46 | } 47 | } -------------------------------------------------------------------------------- /Medium-Questions/05-algorithm-odd/JavaScript/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 |

answer is here

11 | 12 | 13 | https://github.com/alisharifyy/Programming-Questions 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Medium-Questions/05-algorithm-odd/Python/Five.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | def is_even(number): 4 | if (number % 2 == 0): 5 | return True 6 | return False 7 | 8 | 9 | n = int(input()) 10 | if (n < 0): 11 | print("Number must be positive :(") 12 | sys.exit(1) 13 | 14 | print(n,end=" " ) 15 | 16 | while (True): 17 | if (n == 1): 18 | sys.exit(0) 19 | 20 | if (is_even(n)): 21 | n //= 2 22 | print(n,end=" ") 23 | continue 24 | 25 | n *= 3 26 | n += 1 27 | print(n,end=" ") 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /Medium-Questions/05-algorithm-odd/README.md: -------------------------------------------------------------------------------- 1 | # Consider an algorithm that takes as input a positive integer n. If n is even, the algorithm divides it by two, and if n is odd, the algorithm multiplies it by three and adds one. The algorithm repeats this, until n is one. For example, the sequence for n=3 is as follows: 2 | 3 |
4 | 5 | ## 3→10→5→16→8→4→2→1 6 | 7 | 8 | 9 | https://github.com/alisharifyy/Programming-Questions -------------------------------------------------------------------------------- /Medium-Questions/06-circle-Area/C#/six.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace six 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | 14 | // get input from user 15 | Console.Write("Enter R: "); 16 | string temp = Console.ReadLine(); 17 | int r = Int32.Parse(temp); 18 | 19 | // calculate result 20 | // c = 2pr 21 | double answer = (3.1415 * (r ** 2) ); 22 | Console.WriteLine("Answer is {0}", answer); 23 | 24 | Console.ReadKey(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Medium-Questions/06-circle-Area/C/Six.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | float pi = 3.14159265359; 4 | 5 | int main(void) 6 | { 7 | // get input form user 8 | int r; 9 | printf("Enter radius: "); 10 | scanf("%i",&r); 11 | 12 | // calculate area 13 | float n = ( (pi) * (r ** 2)); 14 | 15 | printf("circle of circle is %f ",n); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Medium-Questions/06-circle-Area/JavaScript/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 | 11 |

12 | 13 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Medium-Questions/06-circle-Area/Python/six.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import math 3 | 4 | r = float(input("Enter r: ")) 5 | 6 | # formula for calculate radius of circle 7 | # c = 2pr 8 | # https://www.wikihow.com/Calculate-the-Radius-of-a-Circle 9 | 10 | 11 | p = math.pi 12 | 13 | answer = p * (r ** 2) 14 | 15 | print("Area: ",answer) 16 | 17 | sys.exit(0) 18 | -------------------------------------------------------------------------------- /Medium-Questions/06-circle-Area/README.md: -------------------------------------------------------------------------------- 1 | Write a Python program which accepts the radius of a circle from the user and compute the area. Go to the editor 2 | 3 | 4 |
5 | Sample Output : 6 |
7 | r = 1.1 8 |
9 | Area = 3.8013271108436504 10 | 11 | 12 | https://github.com/alisharifyy/Programming-Questions 13 | -------------------------------------------------------------------------------- /Medium-Questions/07-Reverse-Name/C#/seven.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace seven 8 | { 9 | class Program 10 | { 11 | 12 | public static string Reverse(string s) 13 | { 14 | // convert to array 15 | char[] charArray = s.ToCharArray(); 16 | // Reverse Array 17 | Array.Reverse(charArray); 18 | // return result 19 | return new string(charArray); 20 | } 21 | 22 | static void Main(string[] args) 23 | { 24 | Console.Write("Enter Your Name: "); 25 | string name = Console.ReadLine(); 26 | name = Reverse(name); 27 | 28 | Console.Write(name); 29 | 30 | Console.ReadKey(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Medium-Questions/07-Reverse-Name/C/seven.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(void) 5 | { 6 | 7 | 8 | // reverse a string 9 | char name [40]; 10 | printf("Enter a string: "); 11 | scanf("%s",name); 12 | 13 | printf ("After the reverse of a string: %s ", strrev(name)); 14 | return 0; 15 | 16 | } -------------------------------------------------------------------------------- /Medium-Questions/07-Reverse-Name/JavaScript/seven.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 |

answer is here

11 | 12 | 13 | https://github.com/alisharifyy/Programming-Questions 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Medium-Questions/07-Reverse-Name/JavaScript/seven.js: -------------------------------------------------------------------------------- 1 | let answer = document.getElementById("answer"); 2 | let input_user = prompt("Enter name: ").toString(); 3 | 4 | function text_factory(name) 5 | { 6 | let revesed_txt = ""; 7 | for (let i = (name.length - 1) ; i >= 0 ; i--) 8 | { 9 | // iterate over end to start of string and add it to 10 | // revesed_txt 11 | revesed_txt += name[i]; 12 | } 13 | return revesed_txt; 14 | } 15 | 16 | answer.innerHTML += `
reversed name: ${text_factory(input_user)} `; -------------------------------------------------------------------------------- /Medium-Questions/07-Reverse-Name/Python/seven.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | # get input from user 4 | name = input("name : ") 5 | last_name = input("last name : ") 6 | 7 | # get len of inputs 8 | len1 = len(last_name) 9 | len2 = len(name) 10 | 11 | # interate in last name string 12 | for i in range(len1-1,-1,-1): 13 | print(last_name[i],end="") 14 | print(" ",end="") 15 | 16 | # interate in name string 17 | for i in range(len2-1,-1,-1): 18 | print(name[i],end="") 19 | print(" ",end="") 20 | 21 | 22 | sys.exit(0) -------------------------------------------------------------------------------- /Medium-Questions/07-Reverse-Name/README.md: -------------------------------------------------------------------------------- 1 | Write a Python program which accepts the user's first and last name and print them in reverse order with a space between them. 2 | 3 | 4 | https://github.com/alisharifyy/Programming-Questions -------------------------------------------------------------------------------- /Medium-Questions/08-Ascii-input/C#/eight.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace ascii 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | Console.WriteLine("Enter a single character"); 14 | string temp = Console.ReadLine(); 15 | 16 | if (temp.Length > 1) 17 | { 18 | Console.WriteLine("Input is not a Single Character"); 19 | Console.ReadKey(); 20 | return; 21 | } 22 | 23 | 24 | byte[] ASCIIvalues = Encoding.ASCII.GetBytes(temp); 25 | foreach (var c in ASCIIvalues) 26 | { 27 | if (c >= 48 && c <= 57) 28 | { 29 | Console.WriteLine("Number :) "); 30 | } 31 | else if (c >= 65 && c <= 97) 32 | { 33 | Console.WriteLine("Uper case Alphabet :) "); 34 | } 35 | else if (c >= 97 && c <= 122) 36 | { 37 | Console.WriteLine("Lower case Alphabet :) "); 38 | } 39 | else 40 | { 41 | Console.WriteLine("its a symbol"); 42 | } 43 | 44 | } 45 | 46 | Console.ReadKey(); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Medium-Questions/08-Ascii-input/Python/eight.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | # get input from user 4 | tmp = input("Enter character: ") 5 | 6 | # get ascii value of character 7 | tmp = ord(tmp) 8 | 9 | # if tmp between 48 to 57 so user input is number 10 | if (tmp >= 48 and tmp <= 57): 11 | print("number") 12 | sys.exit(0) 13 | 14 | # if tmp between 65 to 90 so user input is number 15 | elif(tmp >= 65 and tmp <= 90): 16 | print("upper case alphbet") 17 | sys.exit(0) 18 | 19 | # if tmp between 97 to 122 so user input is number 20 | elif(tmp >= 97 and tmp <= 122): 21 | print("Lower case alphabet") 22 | sys.exit(0) 23 | 24 | else: 25 | print("its a symbol") 26 | sys.exit(0) 27 | 28 | # ascii table 29 | # https://www.asciitable.com/asciifull.gif 30 | -------------------------------------------------------------------------------- /Medium-Questions/08-Ascii-input/README.md: -------------------------------------------------------------------------------- 1 | Write a program that takes a character from the user and determines whether the character entered is a capital letter, a small case letter, a digit or a special symbol. The following table shows the range of ASCII values for various characters. 2 | 3 | 4 | 5 | https://github.com/alisharifyy/Programming-Questions -------------------------------------------------------------------------------- /Medium-Questions/09-DateTime/C#/app.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace app 8 | { 9 | internal class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | DateTime now = new DateTime(); 14 | Console.WriteLine(now); 15 | Console.ReadKey(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Medium-Questions/09-DateTime/JavaScript/app.js: -------------------------------------------------------------------------------- 1 | const now = new Date(); 2 | console.log(now.getFullYear(), now.getTime()) -------------------------------------------------------------------------------- /Medium-Questions/09-DateTime/Python/Nine.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import datetime 3 | 4 | 5 | # import time 6 | # x = time.localtime() 7 | # print("Current date and time is") 8 | # print(x[0],x[1],x[2],sep="-",end=" ") 9 | # print(x[3],x[4],x[5],sep=":") 10 | 11 | print(datetime.datetime.now()) 12 | 13 | sys.exit(0) 14 | -------------------------------------------------------------------------------- /Medium-Questions/09-DateTime/README.md: -------------------------------------------------------------------------------- 1 | . Write a Python program to display the current date and time. 2 | Sample Output : 3 |
4 | 5 | Current date and time : 6 | 7 |
8 | 9 | 2014-07-05 14:34:14 10 | 11 | 12 | 13 | https://github.com/alisharifyy/Programming-Questions -------------------------------------------------------------------------------- /Medium-Questions/10-tuple-List/Python/Ten.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | # create empty list and tuple 4 | list_value = [] 5 | top = () 6 | 7 | 8 | user = input("Enter sequence of numbers with comma: ") 9 | 10 | # split user input with <,> and store in list value 11 | list_value = user.split(',') 12 | 13 | # convert list to a tuple 14 | top = tuple(list_value) 15 | 16 | # print both tuple and list 17 | print("LIST: ",list_value) 18 | print("TUPLE: ",top) 19 | 20 | sys.exit(0) -------------------------------------------------------------------------------- /Medium-Questions/10-tuple-List/README.md: -------------------------------------------------------------------------------- 1 | Write a Python program which accepts a sequence of comma-separated numbers from user and generate a list and a tuple with those numbers 2 |
3 | 4 | Sample data : 3, 5, 7, 23 5 | 6 |
7 | 8 | Output : 9 | 10 |
11 | 12 | List : ['3', ' 5', ' 7', ' 23'] 13 | Tuple : ('3', ' 5', ' 7', ' 23') 14 | 15 | 16 | https://github.com/alisharifyy/Programming-Questions -------------------------------------------------------------------------------- /Medium-Questions/11-Three-Sum-N/Python/Eleven.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | list = [] 4 | 5 | # get input from user but in string format 6 | user = input("Enter an integer: ") 7 | 8 | # add user input to a list to can multiple on string 9 | for i in range(1,4): 10 | list.append(user * i) 11 | 12 | 13 | sum = 0 14 | # interate on list and get sum of the list 15 | for i in range(len(list)): 16 | sum += int(list[i]) 17 | 18 | 19 | print(sum) 20 | sys.exit(0) 21 | 22 | -------------------------------------------------------------------------------- /Medium-Questions/11-Three-Sum-N/README.md: -------------------------------------------------------------------------------- 1 | Write a Python program that accepts an integer (n) and computes the value of n+nn+nnn. 2 | 3 |
4 | 5 | Sample value of n is 5 6 | 7 |
8 | 9 | Expected Result : 615 10 | 11 | 5 + 55 + 55 = 615 12 | -------------------------------------------------------------------------------- /Medium-Questions/12-Calender/Python/twelve.py: -------------------------------------------------------------------------------- 1 | import calendar 2 | 3 | year = int(input("Enter year: ")) 4 | month = int(input("Enter Month: ")) 5 | 6 | # https://docs.python.org/3/library/calendar.html 7 | print(calendar.month(year,month)) -------------------------------------------------------------------------------- /Medium-Questions/12-Calender/README.md: -------------------------------------------------------------------------------- 1 | Write a Python program to print the calendar of a given month and year. 2 | 3 | 4 | -------------------------------------------------------------------------------- /Medium-Questions/13-Days-Calculator/C#/app.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Globalization; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace app 9 | { 10 | internal class Program 11 | { 12 | static void Main(string[] args) 13 | { 14 | Console.WriteLine("Enter Dates in format of YYYY/MM/DD"); 15 | Console.Write("ENter Date One: "); 16 | string date_one = Console.ReadLine(); 17 | 18 | Console.Write("ENter Date Two: "); 19 | string date_two = Console.ReadLine(); 20 | 21 | string[] date_one_arr = (date_one.Split('/')); 22 | string[] date_two_arr = (date_two.Split('/')); 23 | 24 | if (date_one_arr.Length != 3 || date_two_arr.Length != 3) 25 | { 26 | Console.WriteLine("Invalid Date;"); 27 | return; 28 | } 29 | try 30 | { 31 | DateTime dt1 = new DateTime(year: Convert.ToInt32(date_one_arr[0]), month: Convert.ToInt32(date_one_arr[1]), day: Convert.ToInt32(date_one_arr[2])) ; 32 | DateTime dt2 = new DateTime(year: Convert.ToInt32(date_two_arr[0]), month: Convert.ToInt32(date_two_arr[1]), day: Convert.ToInt32(date_two_arr[2])) ; 33 | Console.WriteLine(string.Format("{0:d} Days ", Convert.ToString((dt1 - dt2).Days)) ); 34 | } 35 | catch (Exception) 36 | { 37 | 38 | throw; 39 | } 40 | Console.ReadKey(); 41 | 42 | } 43 | 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Medium-Questions/13-Days-Calculator/JavaScript/app.js: -------------------------------------------------------------------------------- 1 | let date1 = new Date(year=2023,month=5,day=8, hour=20); 2 | let date2 = new Date(year=2023,month=5,day=8, hour=18); 3 | console.log(date1); 4 | console.log(date2); 5 | 6 | // result of this statement is Millisecond 7 | let ans = Math.abs(date2 - date1); 8 | // convert to second 9 | ans /= 1000; 10 | // convert to minute 11 | ans /= 60; 12 | // convert to Hour 13 | ans /= 60; 14 | 15 | console.log(`The Delta Between To date is ${ans} Hour`); 16 | -------------------------------------------------------------------------------- /Medium-Questions/13-Days-Calculator/Python/thirteen.py: -------------------------------------------------------------------------------- 1 | from datetime import date 2 | 3 | f_date = list() 4 | s_date = list() 5 | 6 | f = input("Enter fiest Date: ") 7 | s = input("Enter seccond Date: ") 8 | 9 | 10 | 11 | f_date = f.split(",") 12 | s_date = s.split(",") 13 | 14 | f = date(int(f_date[0]),int(f_date[1]),int(f_date[2])) 15 | s = date(int(s_date[0]),int(s_date[1]),int(s_date[2])) 16 | 17 | answer = f - s 18 | 19 | print("Days between date's is => ",answer.days) -------------------------------------------------------------------------------- /Medium-Questions/13-Days-Calculator/README.md: -------------------------------------------------------------------------------- 1 | Write a Python program to calculate number of days between two dates. 2 | 3 |
4 | 5 | Sample dates : (2014, 7, 2), (2014, 7, 11) 6 | 7 |
8 | 9 | Expected output : 9 days -------------------------------------------------------------------------------- /Medium-Questions/14-value-sphere/C#/app.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace app 8 | { 9 | internal class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | //4 / 3 * p * r ** 3 14 | //R = 6.0 15 | int r = 5; 16 | Console.WriteLine(Math.PI); 17 | double result = System.Math.Pow((4 / 3) * System.Math.PI * r , 3); 18 | Console.WriteLine(result); 19 | Console.ReadKey(); 20 | 21 | } 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Medium-Questions/14-value-sphere/Python/Fourteen.py: -------------------------------------------------------------------------------- 1 | import math 2 | # 4 / 3 * p * r ** 3 3 | # R = 6.0 4 | 5 | v = 4 / 3 * math.pi * 6.0 ** 3 6 | print("The volume of the sphere is ==> ",v) -------------------------------------------------------------------------------- /Medium-Questions/14-value-sphere/README.md: -------------------------------------------------------------------------------- 1 | Write a Python program to get the volume of a sphere with radius 6. 2 | 3 | > https://www.bbc.co.uk/bitesize/guides/z9bdb82/revision/1 4 | -------------------------------------------------------------------------------- /Medium-Questions/15-Triangle-Area/C#/fifteen.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace fifteen 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | 14 | // get input and convert it 15 | Console.Write("Enter width: "); 16 | string temp = Console.ReadLine(); 17 | int width = Int32.Parse(temp); 18 | 19 | // get input and convert it 20 | Console.Write("Enter heigth: "); 21 | string temp1 = Console.ReadLine(); 22 | int heigth = Int32.Parse(temp); 23 | 24 | // do calculation 25 | double answer = (width * heigth) * 0.5; 26 | Console.WriteLine("Area is {0}",answer); 27 | 28 | 29 | Console.ReadKey(); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Medium-Questions/15-Triangle-Area/C/fifteen.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | 5 | int main(void) 6 | { 7 | int width; 8 | int height; 9 | 10 | printf("Enter width of triangle:"); 11 | scanf("%d", &width); 12 | 13 | printf("Enter height of triangle:"); 14 | scanf("%d", &height); 15 | 16 | float answer = (width * height) * 0.5; 17 | 18 | 19 | printf("Area is %f", answer); 20 | return 0; 21 | 22 | } -------------------------------------------------------------------------------- /Medium-Questions/15-Triangle-Area/Python/fifteen.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | 4 | height = int(input("Enter height: ")) 5 | width = int(input("Enter width : ")) 6 | 7 | print((height * width) * 0.5) 8 | sys.exit(0) 9 | -------------------------------------------------------------------------------- /Medium-Questions/15-Triangle-Area/README.md: -------------------------------------------------------------------------------- 1 | # Write a Python program that will accept the base and height of a triangle and compute the area. 2 | 3 | 4 | --> https://www.cuemath.com/measurement/area-of-triangle/ 5 | 6 | 7 | 8 | The area of a triangle is defined as the total region that is enclosed by the three sides of any particular triangle. Basically, it is equal to half of the base times height, i.e. A = 1/2 × b × h. 9 | 10 | 11 | 12 | https://github.com/alisharifyy/Programming-Questions -------------------------------------------------------------------------------- /Medium-Questions/16-Missing-Number/Python/sixteen.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | def main(): 4 | n = int(input()) 5 | if not(n >= 2 and n <= (2*10**5) ): 6 | sys.exit(1) 7 | 8 | numbers = input().split() 9 | numbers = [int(each) for each in numbers] 10 | 11 | total_s = n * (n + 1) / 2 12 | print(int(total_s-sum(numbers))) 13 | 14 | 15 | if __name__ == "__main__": 16 | main() -------------------------------------------------------------------------------- /Medium-Questions/16-Missing-Number/README.md: -------------------------------------------------------------------------------- 1 | Missing Number 2 | 3 | You are given all numbers between 1,2,…,n except one. Your task is to find the missing number. 4 | 5 | Input 6 | 7 | The first input line contains an integer n. 8 | 9 | The second line contains n−1 numbers. Each number is distinct and between 1 and n (inclusive). 10 | 11 | Output 12 | 13 | Print the missing number. 14 | 15 | Constraints 16 | 2≤n≤2⋅105 17 | Example 18 | 19 | Input: 20 | 5 21 | 2 3 1 5 22 | 23 | Output: 24 | 4 25 | 26 | --- 27 | --- 28 | 29 | شما تمام اعداد بین 1,2,....,n را دارید به غیر از یکی. وظیفه شما پیدا کردن عدد گم شده است. 30 | 31 | مثال : 32 | 33 | ورودی : 34 | 5 35 | 2 3 1 5 36 | 37 | خروجی : 38 | 4 -------------------------------------------------------------------------------- /Medium-Questions/17-Repetitions/Python/Seventeen.py: -------------------------------------------------------------------------------- 1 | def max_frequency(chars: str) -> tuple: 2 | """ This function returns the element that has the most repetitions in the DNA strand """ 3 | prevous_max = 0 4 | current_max = 0 5 | max_char = "" 6 | A = len(chars) - 1 7 | i = 0 8 | 9 | while i < A: 10 | j = i 11 | current_max = 0 12 | 13 | while A >= j and chars[j] == chars[i]: 14 | current_max += 1 15 | j += 1 16 | 17 | if current_max >= prevous_max: 18 | prevous_max = current_max 19 | max_char = chars[i] 20 | 21 | i += 1 22 | return max_char, prevous_max 23 | 24 | 25 | def main(): 26 | chars = "aaabbbaaabbbbbbbbaaaaaaaaaaababababababababbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" 27 | r = max_frequency(chars=chars) 28 | print(r) 29 | 30 | if __name__ == "__main__": 31 | main() 32 | -------------------------------------------------------------------------------- /Medium-Questions/17-Repetitions/README.md: -------------------------------------------------------------------------------- 1 | Repetitions 2 | 3 | You are given a DNA sequence: a string consisting of characters A, C, G, and T. Your task is to find the longest repetition in the sequence. This is a maximum-length substring containing only one type of character. 4 | 5 | Input 6 | 7 | The only input line contains a string of n characters. 8 | 9 | Output 10 | 11 | Print one integer: the length of the longest repetition. 12 | 13 | Constraints 1≤n≤106 Example 14 | 15 | Input: ATTCGGGA 16 | 17 | Output: 3 18 | 19 | --- 20 | --- 21 | 22 | به شما یک رشته DNA داده میشود: یک رشته متشکل از کاراکتر های A, C, G, T. وظیفه شما پیدا کردن بیشترین تکرار کاراکتر در رشته DNA است. 23 | 24 | مثال : 25 | 26 | ورودی : ATTCGGGA 27 | 28 | خروجی : 3 -------------------------------------------------------------------------------- /Medium-Questions/18-Sum-Cube-Number/Python/eighteen.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | def cube_number(number): 4 | """return sum Cube of the positive number that given to function""" 5 | sum_cube = 0 6 | for i in range(1,number): 7 | sum_cube += i ** 3 8 | 9 | return sum_cube 10 | 11 | 12 | def main(): 13 | try: 14 | user = int(input("Enter a positive number: ")) 15 | except ValueError: 16 | print("That's not a number :( ") 17 | sys.exit(0) 18 | 19 | if(user <= 0): 20 | print("That's not a Positive number") 21 | sys.exit(0) 22 | else: 23 | resualt = cube_number(user) 24 | print("resualt is => %i" % resualt) 25 | sys.exit(0) 26 | 27 | main() 28 | -------------------------------------------------------------------------------- /Medium-Questions/18-Sum-Cube-Number/README.md: -------------------------------------------------------------------------------- 1 | # Write a Python function that takes a positive integer and returns the sum of the cube of all the positive integers smaller than the specified number. 2 | 3 | --- 4 | 5 | ### What is a cube number? 6 | A cube number is the result when a number has been multiplied by itself twice. The symbol for cubed is 3. 7 | 8 | - https://thirdspacelearning.com/blog/what-are-cube-numbers/ 9 | -------------------------------------------------------------------------------- /Medium-Questions/19-Missing-Color/Python/NineTeen.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | first = ["White", "Black", "Red"] 4 | seccond = ["Red", "Green"] 5 | 6 | 7 | 8 | for i in range(len(first)): 9 | temp = first[i] 10 | 11 | if (temp in seccond): 12 | continue 13 | else: 14 | print(temp) 15 | 16 | -------------------------------------------------------------------------------- /Medium-Questions/19-Missing-Color/README.md: -------------------------------------------------------------------------------- 1 | Write a Python program to print out a set containing all the colors from color_list_1 which are not present in color_list_2. 2 | 3 |
4 | 5 | - Test Data : 6 | - color_list_1 = ["White", "Black", "Red"] 7 | - color_list_2 = ["Red", "Green"] 8 | 9 |
10 | 11 | Expected Output : 12 | {'Black', 'White'} 13 | -------------------------------------------------------------------------------- /Medium-Questions/20-Sum-Integer/C#/twenty.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace ConsoleApplication1 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | 14 | Console.Write("Enter a Number: "); 15 | string input = Console.ReadLine(); 16 | int number; 17 | try 18 | { 19 | number = int.Parse(input); 20 | } 21 | catch 22 | { 23 | Console.WriteLine("NaN"); 24 | return; 25 | } 26 | 27 | Console.WriteLine((number * (number + 1) / 2)); 28 | 29 | Console.ReadKey(); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Medium-Questions/20-Sum-Integer/JavaScript/app.js: -------------------------------------------------------------------------------- 1 | const TNumber = 5; 2 | // formula for get sum of all previous numbers is 3 | // (n/2) * (first number + last number) 4 | 5 | console.log((TNumber/2)*(1 + TNumber)) -------------------------------------------------------------------------------- /Medium-Questions/20-Sum-Integer/Python/twenty.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | n = int(input("Enter n: ")) 4 | 5 | # @ hard code way 6 | # ans = 0 7 | # for i in range(n+1): 8 | # ans +=i 9 | # print(ans) 10 | 11 | # @ mathematical way 12 | answer = (n * (n+1) / 2) 13 | print(answer) 14 | 15 | 16 | sys.exit(0) -------------------------------------------------------------------------------- /Medium-Questions/20-Sum-Integer/README.md: -------------------------------------------------------------------------------- 1 | Write a Python program to sum of the first n positive integers 2 |
3 | 4 | 5 | > example: 6 | 7 | - input: 8 8 | - output: 36 9 | 10 |
11 | (n) + (n - 1) + (n - 1) ... + 0 12 | -------------------------------------------------------------------------------- /Medium-Questions/21-ip-validate/JavaScript/app.js: -------------------------------------------------------------------------------- 1 | const ipValid = "1.1.1.1123" 2 | const ipInvalid = "192.168.1.256" 3 | 4 | 5 | console.log(validate_ip(ipValid)) 6 | console.log(validate_ip(ipInvalid)) 7 | 8 | 9 | 10 | function validate_ip(ip){ 11 | const validatorRegex = /^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/ 12 | 13 | let validResult = validatorRegex.test(ip) 14 | if (validResult === true) 15 | { 16 | let splitedIP = ip.split("."); 17 | let is_ok = true; 18 | 19 | splitedIP.forEach((e)=>{ 20 | e = parseInt(e); 21 | if (!(e > 0 && e <= 255)){ 22 | is_ok = false; 23 | return; 24 | } 25 | }) 26 | 27 | return is_ok; 28 | } 29 | else 30 | { 31 | return false; 32 | } 33 | } -------------------------------------------------------------------------------- /Medium-Questions/21-ip-validate/Python/ip.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | # get input from user 4 | user = input("Enter ip: ") 5 | 6 | # defind a list for add ip address to it 7 | names = [] 8 | # split user input and add it to list 9 | names = user.split(".") 10 | 11 | # interate over all list 12 | for i in names: 13 | # try to confirm user input is a int not string 14 | try: 15 | i = int(i) 16 | if i > 0 and i < 255: 17 | continue 18 | else: 19 | # if user input ip is out on range 20 | print("Invalid ip Address") 21 | sys.exit(1) 22 | # if user input is a string quit 23 | except ValueError: 24 | print('It\'s Not a Number :( ') 25 | sys.exit(1) 26 | 27 | # if every this goes fine! 28 | print('Correct ip address') 29 | -------------------------------------------------------------------------------- /Medium-Questions/21-ip-validate/README.md: -------------------------------------------------------------------------------- 1 | # in this problem set write a program that prompt user for a ip address and validate that address is correct or not 2 | 3 | if you don't understand ip see this : https://en.wikipedia.org/wiki/IP_address 4 | 5 | > example: 6 | 7 | input: 192.168.1.289 8 |
9 | output: Invalid ip address 10 | 11 | 12 | input: 192.168.1.1 13 |
14 | output: correct ip address 15 | 16 | 17 | -------------------------------------------------------------------------------- /Medium-Questions/22-Number-2-Bin/Python/Nm2Bin.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | 4 | binary_pow = [] 5 | 6 | try: 7 | user = int(input('Enter Number: ')) 8 | if user < 0: 9 | print('Enter a positive Number :( ') 10 | sys.exit(1) 11 | except ValueError: 12 | print("It's Not a Number") 13 | sys.exit(1) 14 | 15 | 16 | 17 | i = 0 18 | while True: 19 | temp =2**i 20 | binary_pow.append(temp) 21 | i+=1 22 | if temp > user: 23 | break 24 | 25 | binary_pow.reverse() 26 | 27 | for i in binary_pow: 28 | if user >= i: 29 | user -= i 30 | print("1",end='') 31 | else: 32 | print("0",end='') -------------------------------------------------------------------------------- /Medium-Questions/22-Number-2-Bin/README.md: -------------------------------------------------------------------------------- 1 | # Write a program that Get a decimal Number and Convert it to Binary Number 2 | ### notice: you cant use library or method in this problem set 3 | > example : 4 | >>input : 12 5 | >>
6 | >>output : 1100 7 | 8 | 9 | 10 | see https://en.wikipedia.org/wiki/Binary_code for understanding binary Number 11 | -------------------------------------------------------------------------------- /Medium-Questions/23-body-mass-index/Python/Twenty-Three.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | try: 4 | m = float(input('Enter Your Height in Meter: ')) 5 | kg = float(input('Enter Weight in Kilogram: ')) 6 | except ValueError: 7 | print('Invalid input') 8 | sys.exit(0) 9 | 10 | bmi = (kg / (m ** 2)) 11 | print(f'Your BMI is {bmi}') 12 | 13 | if bmi < 18.5: 14 | print('Underweight') 15 | elif(bmi >= 18.5 and bmi <= 24.9): 16 | print('Normal weight') 17 | elif (bmi >= 25.0 and bmi <= 29.9): 18 | print('Obesity - Class One') 19 | elif (bmi >= 30.0 and bmi <= 34.9): 20 | print('Obesity - Class Two') 21 | elif (bmi >= 35.0 and bmi <= 39.9): 22 | print('Obesity - Class Three') 23 | elif (bmi >= 40.0): 24 | print('Obesity - Class Four') 25 | -------------------------------------------------------------------------------- /Medium-Questions/23-body-mass-index/README.md: -------------------------------------------------------------------------------- 1 | # Write a program to calculate body mass index. 2 | 3 | ### if You don't know what is body mass : 4 | Body Mass Index is a simple calculation using a person's height and weight. 5 | The formula is BMI = kg/m2 where kg is a person's weight in kilograms and m2 is their height in metres squared. A BMI of 25.0 or more is overweight, while the healthy range is 18.5 to 24.9. BMI applies to most adults 18-65 years. 6 | 7 | - https://en.wikipedia.org/wiki/Body_mass_index 8 | -------------------------------------------------------------------------------- /Medium-Questions/24-pass-algorithm/Python/Twenty-Four.py: -------------------------------------------------------------------------------- 1 | import statistics as st 2 | import sys 3 | import colorama as color 4 | import random 5 | 6 | color.init() 7 | 8 | def validate(password): 9 | """this function return True if password match with condition otherwise return False""" 10 | 11 | # check length of password 12 | if len(password) > 12 or len(password) < 8: 13 | return False 14 | 15 | # Rule (password should be created with alphabet or Numbers) 16 | for each in password: 17 | # check if i is not number of alphabet so return false 18 | if not each.isdigit() and not each.isalpha(): 19 | return False 20 | return True 21 | 22 | 23 | def Multipl_5(code): 24 | """ this function return Number of element in a list that multiple of 5 """ 25 | total = 0 26 | for each in code: 27 | if each % 5 == 0: 28 | total += each 29 | return total 30 | 31 | 32 | # get input from user 33 | user = input('input a Password: ').lower().strip() 34 | answer = validate(user) 35 | 36 | # check answer returned from function 37 | if not answer: 38 | print('\n[Error]\n -Length of password must between 8 to 12\n -should all password created by Number or alphabet\n ') 39 | sys.exit(1) 40 | 41 | # add all password character ascii code in code array list 42 | code = list(map(lambda x: ord(x) ,user)) 43 | code.sort() 44 | 45 | # add all characters of user input in password array list 46 | password = list(map(lambda x: x ,user)) 47 | 48 | 49 | location_middle = round(len(code) / 2) 50 | # total of first element and last element and middle element 51 | total_a = code[0] + code[-1] + code[location_middle] 52 | total_5 = Multipl_5(code) 53 | 54 | 55 | if total_5 < total_a: 56 | print('Good Password') 57 | sys.exit(0) 58 | elif total_5 > total_a: 59 | print('Bad Password') 60 | sys.exit(0) 61 | else: 62 | rand = random.randint(0,len(password)) 63 | print(rand) 64 | print(f"{color.Fore.BLUE}{user}") 65 | sys.exit(0) 66 | 67 | -------------------------------------------------------------------------------- /Medium-Questions/24-pass-algorithm/Python/requirement.txt: -------------------------------------------------------------------------------- 1 | colorama -------------------------------------------------------------------------------- /Medium-Questions/24-pass-algorithm/README.md: -------------------------------------------------------------------------------- 1 | 1 -می خواهیم برنامه ای برای تشخیص گذرواژه به شکل زیر طراحی کنیم: 2 | ابتدا کاربر باید گذرواژه مورد نظر را نویسه به نویسه در آرایه password وارد و کد اسکی متناظر با هر نویسه را 3 | در آرایه code نگهداری کند.گذرواژه می تواند بین 8 تا 12 نویسه وفقط شامل حروف و اعداد باشد. تعداد نویسه 4 | های گذرواژه را کاربرمشخص می کند. سپس آرایه code را به ترتیب نزولی مرتب کند. 5 | اگر مجموع عناصر مضرب 5 آرایه code از مجموع عناصر اول –وسط وآخر کمتر باشد آنگاه پیام 6 | “Password Good "داده شود و اگر بیشتر باشد پیام "Password Bad "داده شود در غیراینصورت برنامه 7 | بتواند به دنبال یک نویسه دلخواه در آرایه password بگردد و تمام اندیس های پیدا شدن آنرا نمایش دهد. 8 | در آخر گذرواژه با رنگ آبی روی سفید نمایش داده شود . 9 | 10 | منبع : لیگ برنامه نویسی هنرجویان رشته شبه و نرم افزار استان البرز 11 | 12 | ------------- 13 | write a Program that take a password from user 14 | length of password must between 8 to 12 character 15 | store each character of user input in a password list array [] 16 | then store each character ascii code in code list array [] 17 | password should be combination of Number or character 18 | -------------------------------------------------------------------------------- /Medium-Questions/25-Permutations/README.md: -------------------------------------------------------------------------------- 1 | A permutation of integers 1,2,…,n is called beautiful if there are no adjacent elements whose difference is 1. 2 | 3 | Given n, construct a beautiful permutation if such a permutation exists. 4 | 5 | Input 6 | 7 | The only input line contains an integer n. 8 | 9 | Output 10 | 11 | Print a beautiful permutation of integers 1,2,…,n. If there are several solutions, you may print any of them. If there are no solutions, print "NO SOLUTION". 12 | 13 | Constraints 14 | 1≤n≤106 15 | Example 1 16 | 17 | Input: 18 | 5 19 | 20 | Output: 21 | 4 2 5 3 1 22 | 23 | Example 2 24 | 25 | Input: 26 | 3 27 | 28 | Output: 29 | NO SOLUTION -------------------------------------------------------------------------------- /Medium-Questions/26-String-gen/Python/Twenty-six.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import random 3 | 4 | 5 | character= [] 6 | user = input("Enter a String: ") 7 | 8 | for each in user: 9 | character.append(each) 10 | 11 | 12 | chance = len(character) * len(character) 13 | flag = 0 14 | res = '' 15 | 16 | rand_string = [] 17 | while True: 18 | if flag == chance: 19 | break 20 | 21 | for i in user: 22 | temp= [] 23 | rand = random.choice(character) 24 | temp.append(rand) 25 | 26 | for each in temp: 27 | res += character[each] 28 | 29 | 30 | if res not in rand_string: 31 | rand_string.append(res) 32 | res = '' 33 | else: 34 | flag += 1 35 | continue 36 | 37 | 38 | print(len(rand_string)) 39 | print(rand_string) -------------------------------------------------------------------------------- /Medium-Questions/26-String-gen/README.md: -------------------------------------------------------------------------------- 1 | Given a string, your task is to generate all different strings that can be created using its characters. 2 | 3 | Input 4 | 5 | The only input line has a string of length n. Each character is between a–z. 6 | 7 | Output 8 | 9 | First print an integer k: the number of strings. Then print k lines: the strings in alphabetical order. 10 | 11 | Constraints 12 | 1≤n≤8 13 | Example 14 | 15 | Input: 16 | aabac 17 | 18 | Output: 19 | 20 20 | aaabc 21 | aaacb 22 | aabac 23 | aabca 24 | aacab 25 | aacba 26 | abaac 27 | abaca 28 | abcaa 29 | acaab 30 | acaba 31 | acbaa 32 | baaac 33 | baaca 34 | bacaa 35 | bcaaa 36 | caaab 37 | caaba 38 | cabaa 39 | cbaaa -------------------------------------------------------------------------------- /Medium-Questions/27-Math-machine/Python/Twenty-seven.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | 4 | def validate(number): 5 | """This Function validate user data""" 6 | 7 | try: 8 | # validate to user type number not int 9 | first_number = int(number[0]) 10 | second_number = int(number[2]) 11 | except ValueError: 12 | return False 13 | # check user type math operator 14 | if number[1] not in ["+", "-", "/", "*", "**"]: 15 | return False 16 | # return number in tuple mode 17 | return (first_number , second_number,) 18 | 19 | 20 | # get input from user 21 | user = input("Input : ").strip() 22 | 23 | # create a list and split user data in it 24 | num = [] 25 | num = user.split(" ") 26 | 27 | # validate user date 28 | if not validate(num): 29 | print("Invalid input") 30 | sys.exit(1) 31 | else: 32 | # unpack tuple 33 | f_number , sec_number = validate(num) 34 | 35 | 36 | # if user type + 37 | if "+" in user: 38 | try: 39 | answer = f_number + sec_number 40 | print(f"Answer = {answer}") 41 | sys.exit(0) 42 | except Exception as e: 43 | # if math operator is Error 44 | # print Error message 45 | print("Error ",e) 46 | sys.exit(1) 47 | 48 | 49 | # if user type - 50 | if "-" in user: 51 | try: 52 | answer = f_number - sec_number 53 | print(f"Answer = {answer}") 54 | sys.exit(0) 55 | except Exception as e: 56 | print("Error ",e) 57 | sys.exit(1) 58 | 59 | 60 | # if user type / 61 | if "/" in user: 62 | try: 63 | answer = f_number / sec_number 64 | print(f"Answer = {answer}") 65 | sys.exit(0) 66 | except Exception as e: 67 | print("Error ",e) 68 | sys.exit(1) 69 | 70 | # if user type * 71 | if "*" in user: 72 | try: 73 | answer = f_number * sec_number 74 | print(f"Answer = {answer}") 75 | sys.exit(0) 76 | except Exception as e: 77 | print("Error ",e) 78 | sys.exit(1) 79 | 80 | # if user type ** 81 | if "*" in user: 82 | try: 83 | answer = f_number ** sec_number 84 | print(f"Answer = {answer}") 85 | sys.exit(0) 86 | except Exception as e: 87 | print("Error ",e) 88 | sys.exit(1) -------------------------------------------------------------------------------- /Medium-Questions/27-Math-machine/README.md: -------------------------------------------------------------------------------- 1 | Write a program that implements a math calculator with this math operator 2 | 3 |
4 | *
5 | -
6 | +
7 | /
8 | ** 9 | 10 | 11 | 12 | > example : 13 | 14 | input : 2 + 56 15 |
16 | output : 58 17 | ___ 18 | input : 1000 / 2 19 |
20 | output : 500 21 | ___ 22 | input : 0 / 0 23 |
24 | output : Error 25 | -------------------------------------------------------------------------------- /Medium-Questions/28-Find-19/JavaScript/app.js: -------------------------------------------------------------------------------- 1 | // Input: [19, 19, 15, 5, 3, 5, 5, 2] Output: True 2 | // Input: [19, 15, 15, 5, 3, 3, 5, 2] Output: False 3 | // Input: [19, 19, 5, 5, 5, 5, 5] Output: True 4 | 5 | 6 | const listOne = [19, 19, 15, 5, 3, 5, 5, 2] 7 | const listTwo = [19, 15, 15, 5, 3, 3, 5, 2] 8 | const listThere = [19, 19, 5, 5, 5, 5, 5] 9 | 10 | 11 | function validate_list(list){ 12 | let fives = 0; 13 | let nineten = 0; 14 | list.forEach(e => { 15 | if(e == 19){ 16 | nineten += 1; 17 | } 18 | else if(e == 5){ 19 | fives += 1; 20 | } 21 | }); 22 | return fives >= 3 && nineten == 2 ? true : false 23 | } 24 | 25 | console.log(`List One: ${listOne}` ,validate_list(listOne)) 26 | console.log(`List Two: ${listTwo}` ,validate_list(listTwo)) 27 | console.log(`List There: ${listThere}` ,validate_list(listThere)) 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /Medium-Questions/28-Find-19/Python/twenty-eight.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | def search(number): 4 | counter_19 = 0 5 | counter_5 = 0 6 | 7 | for i in number: 8 | i = i.strip() 9 | 10 | if (i == '19'): 11 | counter_19 += 1 12 | continue 13 | 14 | if (i == '5'): 15 | counter_5 += 1 16 | continue 17 | 18 | if counter_19 == 2 and counter_5 >= 3: 19 | return True 20 | return False 21 | 22 | 23 | 24 | user = input("Input: ").strip() 25 | user = user.split(",") 26 | answer = search(user) 27 | 28 | if answer: 29 | print("True") 30 | sys.exit(0) 31 | else: 32 | print("False") 33 | sys.exit(1) -------------------------------------------------------------------------------- /Medium-Questions/28-Find-19/README.md: -------------------------------------------------------------------------------- 1 | 1. Write a program find a list of integers with exactly two occurrences of nineteen and at least three occurrences of five. 2 | 3 | Input: 4 | [19, 19, 15, 5, 3, 5, 5, 2] 5 | Output: 6 | True 7 | 8 | 9 | Input: 10 | [19, 15, 15, 5, 3, 3, 5, 2] 11 | Output: 12 | False 13 | 14 | Input: 15 | [19, 19, 5, 5, 5, 5, 5] 16 | Output: 17 | True -------------------------------------------------------------------------------- /Medium-Questions/30-Piles/Python/thirty.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | def ev(number): 4 | if number % 2 == 0: 5 | return True 6 | return False 7 | 8 | 9 | try: 10 | user = int(input("Enter Number of Piles: ").strip()) 11 | except ValueError: 12 | print("Please Enter a Number") 13 | sys.exit() 14 | 15 | pil = [] 16 | 17 | if ev(user): 18 | pil.append(user) 19 | for i in range(user): 20 | pil.append(pil[i] + 2) 21 | pil.pop() 22 | else: 23 | pil.append(user) 24 | for i in range(user): 25 | pil.append(pil[i] + 2) 26 | pil.pop() 27 | 28 | print(pil) 29 | -------------------------------------------------------------------------------- /Medium-Questions/30-Piles/README.md: -------------------------------------------------------------------------------- 1 | We are making n stone piles! The first pile has n stones. If n is even, then all piles have an even number of stones. If n is odd, all piles have an odd number of stones. Each pile must more stones than the previous pile but as few as possible. Write a program to find the number of stones in each pile. 2 | 3 | 4 | Input: 2 5 | Output: 6 | [2, 4] 7 | 8 | 9 | Input: 10 10 | Output: 11 | [10, 12, 14, 16, 18, 20, 22, 24, 26, 28] 12 | 13 | 14 | Input: 3 15 | Output: 16 | [3, 5, 7] 17 | 18 | 19 | Input: 17 20 | Output: 21 | [17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49] -------------------------------------------------------------------------------- /Medium-Questions/31-Middle-word/Python/Main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | 4 | # get input from user 5 | user = input("Enter a string: ").strip() 6 | 7 | # get middle of string and round it 8 | choice = round(len(user) / 2) 9 | 10 | # print middle character and One character after it 11 | print (user[choice],user[choice+1]) 12 | sys.exit(0) 13 | -------------------------------------------------------------------------------- /Medium-Questions/31-Middle-word/README.md: -------------------------------------------------------------------------------- 1 | source : https://computersciencewiki.org/index.php/Middle_letter 2 | 3 | The Problem 4 | You are going to be given a word. Your job is to return the middle character of the word. If the word's length is odd, return the middle character. If the word's length is even, return the middle 2 characters. 5 | 6 | For example: 7 | 8 | myString = "Torun" 9 | ...should return r, as 'r' is the middle character. 10 | 11 | -------------------------------------------------------------------------------- /Medium-Questions/32-Pass-cracker/Python/pass-cracker.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | # solve this question with list in python 4 | 5 | def find_pass(number): 6 | # convert number to string to be can access to each element in it! 7 | # and with zfill function we force string to be 5 element 8 | number = str(number).zfill(5) 9 | 10 | # in here we check the rules and if rules ok return true 11 | # and with int() type casting we convert string to a number 12 | # to can do math on it 13 | if ( (int(number[4]) + int(number[2]) == 14) and 14 | ( (int(number[1]) * 2 ) - 1 == int(number[0]) ) and 15 | ( (int(number[3]) - 1 ) == int(number[1]) ) and 16 | ( (int(number[1]) + int(number[2]) ) == 10 ) and 17 | (int(number[0]) + int(number[1]) + int(number[2]) + int(number[3]) + int(number[4]) == 30) ): 18 | return True 19 | return False 20 | 21 | 22 | # from here we send from 9999 to 99_999 to find pass function 23 | for num in range(9999,100000): 24 | # if find pass return true so we found passcode 25 | if (find_pass(num)): 26 | print(num) 27 | sys.exit(0) 28 | 29 | -------------------------------------------------------------------------------- /Medium-Questions/32-Pass-cracker/README.md: -------------------------------------------------------------------------------- 1 | solve this question with list data type in python 2 | --------------------------------------------------------- 3 | 4 | معمای ریاضیاتی پیدا کردن رمز گاوصندوق 5 | سینا پین‌کد ۵ رقمی گاوصندوق خود را فراموش کرده است. با این حال، اطلاعاتی درباره اعداد پین‌کد خود دارد 6 | 7 | جمع رقم‌های پنجم و سوم پین‌کد برابر با چهارده است 8 | 9 | رقم اول، یک واحد از دوبرابر رقم‌ دوم کمتر است 10 | 11 | رقم چهارم، یک واحد از رقم دوم بیشتر است 12 | . 13 | جمع رقم‌های دوم و سوم برابر با ده است 14 | 15 | حاصل‌جمع رقم‌های پین‌کد برابر با ۳۰ است 16 | 17 | با توجه به این اطلاعات، پین‌کد سینا را تعیین کنید 18 | -------------------------------------------------------------------------------- /Medium-Questions/33-Smallest-Largest/Python/Main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | def main(): 4 | try: 5 | number = int(input("Enter a Number: ")) 6 | except ValueError: 7 | print("Invalid Input ") 8 | sys.exit(1) 9 | 10 | print(f"Largest Number is {max(str(number))}") 11 | print(f"Smallest Number is {min(str(number))}") 12 | 13 | 14 | if __name__ == "__main__": 15 | main() -------------------------------------------------------------------------------- /Medium-Questions/33-Smallest-Largest/README.md: -------------------------------------------------------------------------------- 1 | # Write a program to find the largest and smallest digit of a given number. 2 | 3 | --- 4 | 5 | Original Number: 9387422 6 | 7 | Largest Digit of the said number: 9 8 | 9 | Smallest Digit of the said number: 2 10 | 11 | ___ 12 | Original Number: 500 13 | 14 | 15 | Largest Digit of the said number: 5 16 | 17 | Smallest Digit of the said number: 0 18 | 19 | ___ 20 | Original Number: 231548 21 | 22 | Largest Digit of the said number: 8 23 | 24 | Smallest Digit of the said number: 1 -------------------------------------------------------------------------------- /Medium-Questions/34-Bitstring/C#/Main.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace main 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | Console.Write("Enter Bit Counts : "); 14 | int bitCount = int.Parse(Console.ReadLine()); 15 | 16 | string result = Math.Pow(2, bitCount).ToString(); 17 | Console.WriteLine("Output : " + result); 18 | Console.ReadKey(); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Medium-Questions/34-Bitstring/Python/Main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | 4 | try: 5 | n = int(input("Enter n: ")) 6 | except ValueError: 7 | print("Invalid input") 8 | sys.exit(1) 9 | 10 | if n >=1 and n <= 106: 11 | print(2**n) 12 | else: 13 | print("Out of Range") 14 | 15 | 16 | -------------------------------------------------------------------------------- /Medium-Questions/34-Bitstring/README.md: -------------------------------------------------------------------------------- 1 | ~ Bit Strings ~ 2 | 3 | Your task is to calculate the number of bit strings of length n. 4 | 5 | For example, if n=3, the correct answer is 8, because the possible bit strings are 000, 001, 010, 011, 100, 101, 110, and 111. 6 | 7 | 8 | Input: 9 | 10 | The only input line has an integer n. 11 | 12 | ___ 13 | 14 | Output: 15 | 16 | Print the result modulo 109+7. 17 | 18 | Constraints 19 | 1≤n≤106 20 | Example 21 | 22 | Input: 23 | 3 24 | 25 | Output: 26 | 8 -------------------------------------------------------------------------------- /Medium-Questions/35-students-Grade/Python/students-Grade.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | 4 | def get_int(message): 5 | """ 6 | This function get input from user 7 | ONLY int input 8 | """ 9 | 10 | while True: 11 | n = input(message) 12 | try: 13 | n = int(n) 14 | return n 15 | except ValueError: 16 | continue 17 | 18 | def get_student(round): 19 | """ 20 | this function take students name and grade 21 | and return in form of dict object 22 | """ 23 | 24 | n = input(f"Enter student #{round + 1}# name ? ") 25 | g = input(f"Enter student #{round + 1}# Grade ? ") 26 | 27 | return {"name":n, "grade":g} 28 | 29 | 30 | 31 | def remove_biggest(data): 32 | """ 33 | this function remove student with biggest Grade 34 | from list and return list 35 | """ 36 | first = 0 37 | deleted = 0 38 | for each in enumerate(data): 39 | temp = int(each[1]["grade"]) 40 | if temp >= first: 41 | first = temp 42 | deleted = each[0] 43 | 44 | del data[deleted] 45 | return data 46 | 47 | 48 | 49 | def find_biggest(data): 50 | """ 51 | this function find student with biggest grade 52 | and return it 53 | """ 54 | first = 0 55 | biggest = 0 56 | for each in data: 57 | temp = int(each["grade"]) 58 | if temp >= first: 59 | first = temp 60 | biggest = each 61 | return biggest 62 | 63 | def main(): 64 | # get number of student from user 65 | n_student = get_int("Enter students Number: ") 66 | 67 | total = [] 68 | # get all student and store it in total list 69 | for i in range(n_student): 70 | temp = get_student(i) 71 | total.append(temp) 72 | 73 | # remove student with biggest grade 74 | total = remove_biggest(total) 75 | # find student with biggest grade {second} - because we remove first one 76 | second = find_biggest(total) 77 | 78 | 79 | print(f"{second['name']} is Second student in class with Grade {second['grade']}") 80 | 81 | 82 | if __name__ == '__main__': 83 | main() 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /Medium-Questions/35-students-Grade/README.md: -------------------------------------------------------------------------------- 1 | # کاردانی نرم افزار دانشکده پسران یزد 2 | 3 | 4 | برنامه ای که شماره دانشجویی و معدل تعدادی دانشجو را از ورودی خوانده و دانشجویی که دومین معدل را از نظر بزرگی دارد پیدا کند و به خروجی ببرد -------------------------------------------------------------------------------- /Medium-Questions/36-perfect-number/Python/perfect_number.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | 4 | def get_int(message): 5 | """ 6 | This function get input from user 7 | ONLY int input 8 | """ 9 | 10 | n = input(message).split(',') 11 | numbers = [] 12 | for each in n: 13 | try: 14 | each =int(each) 15 | except ValueError: 16 | print("Invalid format Number") 17 | sys.exit(1) 18 | else: 19 | numbers.append(each) 20 | return numbers 21 | 22 | 23 | def is_perfect(number): 24 | maqsom = [] 25 | for i in range(1,number): 26 | if number % i == 0: 27 | maqsom.append(i) 28 | total = 0 29 | for each in maqsom: 30 | total+= each 31 | if total == number: 32 | return True 33 | return False 34 | 35 | def main(): 36 | print(""" 37 | Enter list of Number 38 | in format of => 1,2,3,4,5,6 39 | """) 40 | n = get_int("prompt: ") 41 | for i in n: 42 | 43 | if is_perfect(i): 44 | print(f"{i} is perfect number") 45 | n = input("Do you wanna continue? [y,n]: ") 46 | if n.upper() in ["N", "NO"]: 47 | sys.exit("Exit !") 48 | 49 | if not is_perfect(i): 50 | print(f"{i} is not perfect number") 51 | n = input("Do you wanna continue? [y,n]: ") 52 | if n.upper() in ["N", "NO"]: 53 | sys.exit("Exit !") 54 | 55 | 56 | 57 | 58 | 59 | 60 | if __name__ == '__main__': 61 | main() -------------------------------------------------------------------------------- /Medium-Questions/36-perfect-number/README.md: -------------------------------------------------------------------------------- 1 | # کاردانی نرم افزار دانشکده پسران یزد 2 | 3 | 4 | برنامه ای بنویسید که تعدادی اعداد را از ورودی خوانده و تشخیص دهد ایا عدد مورد نظر کامل است یا خیر, پس از بررسی هر عدد از کاربر سوال کند که میخواهد ادامه دهد یا خیر؟ 5 | 6 | عددی کامل است که مجموع مقسوم علیه هایش (به جز خودش) با خودش برابر باشد 7 | 8 | https://en.wikipedia.org/wiki/Perfect_number 9 | -------------------------------------------------------------------------------- /Medium-Questions/37-avg-Employee/Python/employee.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from tabulate import tabulate 3 | 4 | def get_int(msg): 5 | """Return only int input otherwise continue loop""" 6 | while True: 7 | n = input(msg).strip() 8 | try: 9 | n = int(n) 10 | except ValueError: 11 | continue 12 | else: 13 | return n 14 | 15 | 16 | def get_pay(msg): 17 | """Return only pay number between 1-9 otherwise continue loop""" 18 | while True: 19 | n = input(msg).strip() 20 | try: 21 | n = int(n) 22 | if 0 < n < 10: 23 | return n 24 | else: 25 | continue 26 | except ValueError: 27 | continue 28 | else: 29 | return n 30 | 31 | def get_sex(msg): 32 | """Return only sex type of employees [0 , 1] otherwise continue loop""" 33 | while True: 34 | n = input(msg).strip() 35 | if n in ["1", "0"]: 36 | return n 37 | else: 38 | continue 39 | 40 | def get_employees(): 41 | """ 42 | this function take all employees 43 | """ 44 | employees = [] 45 | counter = 0 46 | while True: 47 | if counter != 0: 48 | flag = input("That's all the employees? (YES,NO): ") 49 | if (flag.upper() in ["YES", "Y"]): 50 | return employees 51 | counter += 1 52 | name = input(f"Enter Employee {counter} Name: ").strip() 53 | sex = get_sex(f"Enter Employee {counter} sex (1=man, 0=woman): ").strip() 54 | year = input(f"Enter Employee {counter} year: ").strip() 55 | pay = get_pay(f"Enter Employee {counter} pay: ") 56 | 57 | employe = { 58 | "name": name, 59 | "sex":sex, 60 | "year":year, 61 | "pay":pay 62 | } 63 | employees.append(employe) 64 | 65 | 66 | def find_eployee(data, flag): 67 | """ 68 | this function take an searchable object and search into it 69 | to seach for flag and return number of all flag 70 | """ 71 | counter = 0 72 | for e in data: 73 | if e["sex"] == flag: 74 | counter += 1 75 | return counter 76 | 77 | def get_avg_pay(data, sex): 78 | """ 79 | this function take and sex and search into data 80 | and return average of pay for all employees with input sex 81 | """ 82 | counter = 0 83 | pay = 0 84 | for e in data: 85 | if e["sex"] == sex: 86 | counter += 1 87 | pay = e["pay"] 88 | 89 | return pay / counter 90 | 91 | 92 | def main(): 93 | employees = get_employees() 94 | # get numebr of employees 95 | 96 | n_woman = find_eployee(data=employees, flag="0") 97 | n_man = find_eployee(data=employees, flag="1") 98 | avg_woman_pay = get_avg_pay(employees, sex="0") 99 | avg_man_pay = get_avg_pay(employees, sex="1") 100 | all_employes = len(employees) 101 | table = [ 102 | ["all employes", all_employes], 103 | ["number of womans", n_woman], 104 | ["number of mans", n_man], 105 | ["average of pay for womans", avg_woman_pay], 106 | ["average of pay for mans", avg_man_pay] 107 | ] 108 | print(tabulate(table, tablefmt="grid")) 109 | 110 | 111 | 112 | if __name__ == '__main__': 113 | main() -------------------------------------------------------------------------------- /Medium-Questions/37-avg-Employee/doc/Capture.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/37-avg-Employee/doc/Capture.PNG -------------------------------------------------------------------------------- /Medium-Questions/37-avg-Employee/readme.md: -------------------------------------------------------------------------------- 1 | # کاردانی نرم افزار واحد پسرانه یزد 2 | 3 | 4 | برنامه ای بنویسید که اطلاعات تعدادی کارمند از قبلی شماره کارمندی و سال استخدام کد جنسیت (0 زن | 1مرد) 5 | پایه استخدام را دریافت کرده (1-9) 6 | و موارد زیر را در خروجی چاپ کند 7 | 8 | تعداد کارمندان 9 | تعداد کارکنان زن 10 | میانگین حقوق به تفکیک زن و مرد 11 | 12 | 13 | توجه حقوق باید بین 1 - 9 باشد و نوع جنسیت باید بین 1 - 0 باشد در غیر این صورت دوباره درخواست شود 14 | 15 | مثال: 16 | 17 | output: 18 | 19 | 20 | -------------------------------------------------------------------------------- /Medium-Questions/38-shop-percentage/Python/shop.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | 4 | def get_int(msg): 5 | while True: 6 | n = input(msg).strip() 7 | try: 8 | n = int(n) 9 | except ValueError: 10 | continue 11 | else: 12 | return n 13 | 14 | def get_product(): 15 | """ 16 | this function take and product information and return in 17 | format of dict {} 18 | """ 19 | while True: 20 | price = get_int("Enter Product price: ") 21 | degree = get_int("Enter Product degree: ") 22 | if degree in [1,2,3,4]: 23 | return {"price" : price, "degree": degree} 24 | else: 25 | print("Invalid input. try again") 26 | continue 27 | 28 | def process_procuts(info): 29 | """ 30 | this function calculate seller percentage of this product 31 | """ 32 | if info["degree"] == 1: 33 | if info["price"] <= 1_000_000: 34 | return 6 * info["price"] / 100 35 | elif 1_000_000 < info["price"] > 2_000_000: 36 | return 7 * info["price"] / 100 37 | else: 38 | return 10 * info["price"] / 100 39 | 40 | if info["degree"] == 2: 41 | if info["price"] < 1_00_000: 42 | return 4 * info["price"] / 100 43 | else: 44 | return 6 * info["price"] / 100 45 | if info["degree"] == 3: 46 | return 41.2 * info["price"] / 100 47 | if info["degree"] == 4: 48 | return 5 * info["price"] / 100 49 | 50 | 51 | def main(): 52 | procuts_info = get_product() 53 | seller = process_procuts(procuts_info) 54 | 55 | print(f"Seller percentage is ${seller} of ${procuts_info['price']} ") 56 | 57 | 58 | if __name__ == '__main__': 59 | main() -------------------------------------------------------------------------------- /Medium-Questions/38-shop-percentage/doc/output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/38-shop-percentage/doc/output.PNG -------------------------------------------------------------------------------- /Medium-Questions/38-shop-percentage/doc/question.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/38-shop-percentage/doc/question.PNG -------------------------------------------------------------------------------- /Medium-Questions/38-shop-percentage/readme.md: -------------------------------------------------------------------------------- 1 | # کاردانی نرم افزار واحد پسرانه یزد 2 | 3 | 4 | سوال: 5 | 6 | 7 | خروجی: 8 | -------------------------------------------------------------------------------- /Medium-Questions/39-Rock-Paper-Scissors/Python/app.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import random 3 | 4 | 5 | options = ["rock", "paper", "sissors"] 6 | 7 | 8 | def pic_random(): 9 | """ 10 | this function take a random option between rock-paper-sessors 11 | """ 12 | op = random.choice(options) 13 | return op 14 | 15 | 16 | def get_valid_option(msg): 17 | """ 18 | this function only take valid input from user 19 | """ 20 | while True: 21 | n = input(msg).strip() 22 | if n in ["1", "2", "3"]: 23 | return options[int(n) - 1] 24 | else: 25 | print("invalid option Please select Between 1,2,3 ") 26 | continue 27 | 28 | 29 | def main(): 30 | user = 0 31 | bot = 0 32 | user_selected = [] 33 | bot_selected = [] 34 | 35 | for each in range(5): 36 | # get user input 37 | select_user = get_valid_option(f"Select Your {each + 1} option: ") 38 | user_selected.append(select_user) 39 | 40 | # get random option 41 | select_bot = pic_random() 42 | bot_selected.append(select_bot) 43 | 44 | for index,value in enumerate(user_selected): 45 | if value == bot_selected[index]: 46 | user +=1 47 | bot +=1 48 | continue 49 | 50 | if value == "rock" and bot_selected[index] != "paper": 51 | user += 1 52 | continue 53 | if value == "sissors" and bot_selected[index] != "rock": 54 | user += 1 55 | continue 56 | if value == "paper" and bot_selected[index] != "sissors": 57 | user += 1 58 | continue 59 | bot += 1 60 | 61 | 62 | 63 | print(f"bot: {bot} | you: {user}") 64 | for index, value in enumerate(user_selected): 65 | print(f"You: {value} Bot={bot_selected[index]}") 66 | 67 | if bot > user: 68 | print ("\t\t\t\tBot win !") 69 | elif bot < user: 70 | print ("\t\t\t\tYou win !") 71 | else: 72 | print ("\t\t\t\tgame Tie !") 73 | 74 | 75 | 76 | if __name__ == '__main__': 77 | main() -------------------------------------------------------------------------------- /Medium-Questions/39-Rock-Paper-Scissors/doc/output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/39-Rock-Paper-Scissors/doc/output.png -------------------------------------------------------------------------------- /Medium-Questions/39-Rock-Paper-Scissors/doc/question.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/39-Rock-Paper-Scissors/doc/question.png -------------------------------------------------------------------------------- /Medium-Questions/39-Rock-Paper-Scissors/readme.md: -------------------------------------------------------------------------------- 1 | سوال: 2 | 3 | 4 | خروجی: 5 | 6 | -------------------------------------------------------------------------------- /Medium-Questions/40-Car-20/Python/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | 4 | 5 | def get_percentage(p, value): 6 | """ 7 | this function take a percentage and value and 8 | calculate the percentage of the value 9 | """ 10 | return p * value / 100 11 | 12 | 13 | 14 | def get_int(msg): 15 | """Return only int input otherwise continue loop""" 16 | while True: 17 | n = input(msg).strip() 18 | try: 19 | n = float(n) 20 | except ValueError: 21 | continue 22 | else: 23 | return n 24 | 25 | 26 | def main(): 27 | price = get_int("Enter Car Price: ") 28 | 29 | for year in range(10): 30 | per = get_percentage(20, price) 31 | price -= per 32 | print(f"in year {year + 1} car price is {price}") 33 | 34 | 35 | if __name__ == '__main__': 36 | main() -------------------------------------------------------------------------------- /Medium-Questions/40-Car-20/doc/output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/40-Car-20/doc/output.png -------------------------------------------------------------------------------- /Medium-Questions/40-Car-20/doc/question.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/40-Car-20/doc/question.png -------------------------------------------------------------------------------- /Medium-Questions/40-Car-20/readme.md: -------------------------------------------------------------------------------- 1 | # کاردانی نرم افزار واحد پسرانه یزد 2 | 3 | 4 | سوال: 5 | 6 | 7 | 8 | خروجی: 9 | -------------------------------------------------------------------------------- /Medium-Questions/41-Radical-factorial/Python/math.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | def factorial(n): 4 | """ 5 | This function take an number and 6 | return factorial of that number 7 | """ 8 | if n == 1: 9 | return 1 10 | 11 | return factorial(n - 1) * n 12 | 13 | 14 | def radical(n): 15 | """ 16 | this function take an number and return 17 | radical of that number 18 | """ 19 | return n ** 0.5 20 | 21 | 22 | def get_int(msg): 23 | """ 24 | this function only return integer number 25 | """ 26 | while True: 27 | n = input(msg) 28 | try: 29 | n = int(n) 30 | except ValueError: 31 | continue 32 | else: 33 | return n 34 | 35 | 36 | def main(): 37 | # get number from user 38 | number = get_int("Enter a Number: ") 39 | result = 0 40 | for each in range(1,number+1): 41 | result += (radical(each) / each) - (factorial(each) / (each ** 2)) 42 | 43 | print(result) 44 | 45 | 46 | if __name__ == '__main__': 47 | main() 48 | -------------------------------------------------------------------------------- /Medium-Questions/41-Radical-factorial/doc/question.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/41-Radical-factorial/doc/question.png -------------------------------------------------------------------------------- /Medium-Questions/41-Radical-factorial/readme.md: -------------------------------------------------------------------------------- 1 | # کاردانی نرم افزار واحد پسرانه یزد 2 | 3 | سوال : 4 | 5 | 6 | -------------------------------------------------------------------------------- /Medium-Questions/42-Multiples of 3 or 5/Python/app.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | def is_ok(n): 4 | """ 5 | this function take number and return a Boolean 6 | and check if input number is multiple of 5 or 3 7 | """ 8 | return (n % 3 == 0 or n % 5 == 0) 9 | 10 | 11 | 12 | def main(): 13 | 14 | result = 0 15 | # iterate over all numbers 16 | for i in range(1000): 17 | # check for multiple of 5 or 3 18 | if is_ok(i): 19 | # if its ok 20 | result += i 21 | 22 | print(f"sum of all the multiple of 5 or 3 below 100 is {result}") 23 | 24 | 25 | 26 | if __name__ == '__main__': 27 | main() -------------------------------------------------------------------------------- /Medium-Questions/42-Multiples of 3 or 5/README.md: -------------------------------------------------------------------------------- 1 | # Multiples of 3 or 5 2 | 3 | ### Problem 1 4 | #### If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. 5 | 6 | #### Find the sum of all the multiples of 3 or 5 below 1000. 7 | 8 | https://en.wikipedia.org/wiki/Natural_number 9 | 10 | --- 11 | 12 | سوال 1 13 | 14 | اگر همه اعداد طبیعی کوچکتر از 10 را که مضرب 3 یا 5 هستند بنویسیم، اعداد 3، 5، 6 و 9 بدست می آید. مجموع این اعداد 23 است. 15 | مجموع همه اعداد طبیعی کوچکتر از 1000 را که مضرب 3 یا 5 هستند بیابید. 16 | 17 | https://fa.wikipedia.org/wiki/%D8%B9%D8%AF%D8%AF_%D8%B7%D8%A8%DB%8C%D8%B9%DB%8C 18 | 19 | https://blog.faradars.org/%D8%A7%D8%B9%D8%AF%D8%A7%D8%AF-%D8%B7%D8%A8%DB%8C%D8%B9%DB%8C/ -------------------------------------------------------------------------------- /Medium-Questions/43-Even Fibonacci numbers/Python/app.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | 4 | def generate_fib(number): 5 | """ 6 | this function get a number and return a 7 | sequence of fibonacci number to that number 8 | """ 9 | fib_sequence = [] 10 | a = 0 11 | b = 1 12 | c = 0 13 | while True: 14 | c = a + b 15 | fib_sequence.append(c) 16 | a = b 17 | b = c 18 | if c >= number: 19 | return fib_sequence 20 | return fib_sequence 21 | 22 | 23 | def main(): 24 | f = generate_fib(4_000_000) 25 | f = [each for each in f if each % 2 == 0] 26 | print(sum(f)) 27 | 28 | 29 | if __name__ == '__main__': 30 | main() -------------------------------------------------------------------------------- /Medium-Questions/43-Even Fibonacci numbers/readme.md: -------------------------------------------------------------------------------- 1 | # Even Fibonacci numbers 2 | 3 | ## Problem 2 4 | 5 | ### Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 6 | 7 | 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... 8 | 9 | ### By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms. 10 | 11 | 12 | https://en.wikipedia.org/wiki/Fibonacci_number 13 | 14 | --- 15 | 16 | سوال 2 17 | 18 | در هر دنباله از اعداد فیبوناچی هر عدد با توجه به جمع 2 عدد قبلی خود ساخته میشود 19 | برای مثال با شروع عدد 1 و 2 دنبالی زیر ساخته میشود 20 | 21 | 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... 22 | 23 | با توجه به این قانون جمع اعداد زوج زیر چهار میلیون را بدست اوردید 24 | 25 | https://fa.wikipedia.org/wiki/%D8%A7%D8%B9%D8%AF%D8%A7%D8%AF_%D9%81%DB%8C%D8%A8%D9%88%D9%86%D8%A7%DA%86%DB%8C -------------------------------------------------------------------------------- /Medium-Questions/44-Cipher-Location/Python/app.py: -------------------------------------------------------------------------------- 1 | import os, sys, string 2 | 3 | upper = " ".join(string.ascii_uppercase).split() 4 | lower = " ".join(string.ascii_lowercase).split() 5 | 6 | 7 | def find_loc(n): 8 | """ 9 | this function return location of input in upper or lower list 10 | """ 11 | n = n.strip() 12 | if n.isalpha(): 13 | if n.isupper(): 14 | return upper.index(n) 15 | if n.islower(): 16 | return lower.index(n) 17 | 18 | 19 | def cipher(char, key): 20 | """ 21 | this function return cipher of input text => text 22 | """ 23 | if char.isalpha(): 24 | if char.islower(): 25 | return lower[((find_loc(char) + key) % 26)] 26 | if char.isupper(): 27 | return upper[((find_loc(char) + key) % 26)] 28 | return char 29 | 30 | 31 | def main(): 32 | message = input("Enter a Message: ") 33 | 34 | for index,value in enumerate(message): 35 | print(cipher(value, index), end="") 36 | 37 | 38 | if __name__ == '__main__': 39 | main() -------------------------------------------------------------------------------- /Medium-Questions/44-Cipher-Location/README.md: -------------------------------------------------------------------------------- 1 | برنامه ای بنویسید که متنی را ورودی خوانده آن را رمزنگاری کند 2 | 3 | 4 | مثال: 5 | AB 6 | 7 | خروجی: 8 | AC 9 | 10 | نحوه رمزنگاری : 11 | هر کاراکتر رو باید بر اساس لوکیشن اون کاراکتر باید شیفت بشه به جلو 12 | یعنی کلمه ABC رو اگر بخواییم رمزنگاری کنیم 13 | باید حرف A که در جایگاه 0 ام هست رو هیچی شیفت ندیم 14 | حرف B در جایگاه اول هست باید یک کاراکتر شیفت بدیم 15 | , حرف C که در چایگاه دوم هست رو باید دو کاراکتر شیفت بدیم جلو 16 | 17 | 18 | 19 | لوکشین حروف رو میتونید بر اساس ایندکس آرایه ها هم از 0 بشمارید یا 1 20 | 21 | 22 | 23 | https://en.wikipedia.org/wiki/Caesar_cipher 24 | 25 | 26 | https://fa.wikipedia.org/wiki/%D8%B1%D9%85%D8%B2_%D8%B3%D8%B2%D8%A7%D8%B1 27 | -------------------------------------------------------------------------------- /Medium-Questions/45-Number-methods/Doc/ans1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/45-Number-methods/Doc/ans1.png -------------------------------------------------------------------------------- /Medium-Questions/45-Number-methods/Doc/ans2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/45-Number-methods/Doc/ans2.png -------------------------------------------------------------------------------- /Medium-Questions/45-Number-methods/Doc/ans3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/45-Number-methods/Doc/ans3.png -------------------------------------------------------------------------------- /Medium-Questions/45-Number-methods/Doc/ans4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/45-Number-methods/Doc/ans4.png -------------------------------------------------------------------------------- /Medium-Questions/45-Number-methods/Doc/question.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/45-Number-methods/Doc/question.png -------------------------------------------------------------------------------- /Medium-Questions/45-Number-methods/Python/main.py: -------------------------------------------------------------------------------- 1 | import os, sys 2 | 3 | 4 | class number: 5 | """ 6 | meta class for numbers 7 | in this class all methods available 8 | """ 9 | def all_2digit_equal(self): 10 | print("\33[1m \33[32m --start of All 2 digit numbers that first number and second is qual \33[0m") 11 | for i in range(1,101): 12 | if len(str(i)) == 2: 13 | temp = str(i) 14 | if temp[0] == temp[1]: 15 | print(i, end=" - ") 16 | print("") 17 | return("\33[1m \33[32m --End of start of All 2 digit numbers that first number and second is qual \33[0m") 18 | 19 | def all_3digit_middle_zero(self): 20 | print("\33[1m \33[32m --start of All 3 digit numbers that middle number is zero \33[0m") 21 | for i in range(100,1000): 22 | temp = str(i) 23 | if temp[1] == "0": 24 | print(i, end=" - ") 25 | print("") 26 | return("\33[1m \33[32m --End of All 3 digit numbers that middle number is zero \33[0m") 27 | 28 | def first_second_second(self): 29 | print("\33[1m \33[32m --start of All 3 digit numbers that sum of first number and second is less than third\33[0m") 30 | for i in range(100,1000): 31 | temp = str(i) 32 | if int(temp[1]) + int(temp[0]) < int(temp[2]): 33 | print(i, end=" - ") 34 | print("") 35 | return ("\33[1m \33[32m --End of All 3 digit numbers that sum of first number and second is less than third \33[0m") 36 | 37 | def mirror_number(self): 38 | print("\33[1m \33[32m --start of All 4 digit numbers that each number is mirror \33[0m") 39 | for i in range(1_000,10_000): 40 | temp = str(i) 41 | if temp[0] == temp[-1] and temp[1] == temp[-2]: 42 | print(i, end=" - ") 43 | print("") 44 | return ("\33[1m \33[32m --End of All 4 digit numbers that each number is mirror\33[0m") 45 | 46 | 47 | 48 | def main(): 49 | n = number() 50 | print(n.all_2digit_equal()) 51 | print(n.all_3digit_middle_zero()) 52 | print(n.first_second_second()) 53 | print(n.mirror_number()) 54 | 55 | 56 | 57 | 58 | 59 | if __name__ == '__main__': 60 | main() -------------------------------------------------------------------------------- /Medium-Questions/45-Number-methods/README.md: -------------------------------------------------------------------------------- 1 | # کاردانی نرم افزار واحد پسرانه یزد 2 | 3 | 4 | سوال: 5 | 6 | 7 | 8 | 9 | 10 | خروجی: 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Medium-Questions/46-teacher's-salary/README.md: -------------------------------------------------------------------------------- 1 | # کاردانی نرم افزار واحد پسرانه یزد 2 | 3 | 4 | 5 | سوال: 6 | 7 | 8 | 9 | 10 | 11 | خروجی: 12 | 13 | 14 | -------------------------------------------------------------------------------- /Medium-Questions/46-teacher's-salary/doc/answer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/46-teacher's-salary/doc/answer.png -------------------------------------------------------------------------------- /Medium-Questions/46-teacher's-salary/doc/question.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/46-teacher's-salary/doc/question.png -------------------------------------------------------------------------------- /Medium-Questions/46-teacher's-salary/python/main.py: -------------------------------------------------------------------------------- 1 | import os, sys 2 | 3 | 4 | class Teacher: 5 | 6 | def __init__(self, salary): 7 | try: 8 | salary = float(salary) 9 | except ValueError: 10 | raise ValueError("Salary must be Number") 11 | else: 12 | self.salary = salary 13 | 14 | def calculate_salary(self): 15 | if self.salary < 4_000_000: 16 | return f"Teacher Salary: {4_000_000 + 0.5 * self.salary / 100}\n 0.5% of \33[32m {self.salary} \33[0m => {0.5 * self.salary / 100}" 17 | if self.salary >= 4_000_000 or self.salary < 7_000_000: 18 | return f"Teacher Salary: {self.salary + 12 * self.salary / 100}\n 12% of \33[32m {self.salary} \33[0m => {12 * self.salary / 100}" 19 | if self.salary > 7_000_000: 20 | return f"Teacher Salary: {self.salary + 10 * self.salary / 100}\n 10% of \33[32m {self.salary} \33[0m => {10 * self.salary / 100}" 21 | 22 | 23 | def main(): 24 | teacher = Teacher(58040000) 25 | print(teacher.calculate_salary()) 26 | 27 | 28 | 29 | if __name__ == '__main__': 30 | main() -------------------------------------------------------------------------------- /Medium-Questions/47-power-of-n/Python/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | 4 | def main(): 5 | n = input("Enter a Number:") 6 | try: 7 | n = int(n) 8 | except ValueError: 9 | sys.exit("Input Must be Integer") 10 | 11 | for i in range(n+1): 12 | print(f"2^{i} = \33[32m {2**i}\33[0m") 13 | 14 | 15 | if __name__ == '__main__': 16 | main() -------------------------------------------------------------------------------- /Medium-Questions/47-power-of-n/doc/answer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/47-power-of-n/doc/answer.png -------------------------------------------------------------------------------- /Medium-Questions/47-power-of-n/doc/question.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/47-power-of-n/doc/question.png -------------------------------------------------------------------------------- /Medium-Questions/47-power-of-n/readme.md: -------------------------------------------------------------------------------- 1 | # کارشناسی نرم افزار واحد پسرانه شماره یک یزد 2 | 3 | سوال: 4 | 5 | 6 | 7 | خروجی: 8 | 9 | -------------------------------------------------------------------------------- /Medium-Questions/48-n-Div-Fac(n)/Python/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | 4 | 5 | def factorial(n): 6 | if n == 1: 7 | return 1 8 | return n * factorial(n - 1) 9 | 10 | 11 | def main(): 12 | n = input("Enter a Number:") 13 | try: 14 | n = int(n) 15 | except ValueError: 16 | sys.exit("Input Must be Integer") 17 | 18 | print(f"Answer of 1 / {factorial(n)} ==> {1/factorial(n)}") 19 | 20 | 21 | if __name__ == '__main__': 22 | main() -------------------------------------------------------------------------------- /Medium-Questions/48-n-Div-Fac(n)/doc/answer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/48-n-Div-Fac(n)/doc/answer.png -------------------------------------------------------------------------------- /Medium-Questions/48-n-Div-Fac(n)/doc/question.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/48-n-Div-Fac(n)/doc/question.png -------------------------------------------------------------------------------- /Medium-Questions/48-n-Div-Fac(n)/readme.md: -------------------------------------------------------------------------------- 1 | # کارشناسی نرم افزار واحد پسرانه شماره یک یزد 2 | 3 | سوال: 4 | 5 | 6 | 7 | خروجی: 8 | 9 | -------------------------------------------------------------------------------- /Medium-Questions/49-multiple-without-multiple/Python/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | 4 | 5 | def factorial(n): 6 | if n == 1: 7 | return 1 8 | return n * factorial(n - 1) 9 | 10 | 11 | def main(): 12 | f = input("Enter First Number:") 13 | try: 14 | f = int(f) 15 | except ValueError: 16 | sys.exit("Input Must be Integer") 17 | 18 | s = input("Enter Second Number:") 19 | try: 20 | s = int(s) 21 | except ValueError: 22 | sys.exit("Input Must be Integer") 23 | 24 | result = 0 25 | for i in range(f): 26 | result += s 27 | 28 | print(result) 29 | 30 | 31 | if __name__ == '__main__': 32 | main() -------------------------------------------------------------------------------- /Medium-Questions/49-multiple-without-multiple/doc/answer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/49-multiple-without-multiple/doc/answer.png -------------------------------------------------------------------------------- /Medium-Questions/49-multiple-without-multiple/doc/question.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/49-multiple-without-multiple/doc/question.png -------------------------------------------------------------------------------- /Medium-Questions/49-multiple-without-multiple/readme.md: -------------------------------------------------------------------------------- 1 | # کارشناسی نرم افزار واحد پسرانه شماره یک یزد 2 | 3 | سوال: 4 | 5 | 6 | 7 | خروجی: 8 | 9 | -------------------------------------------------------------------------------- /Medium-Questions/50-n-factorial/doc/answer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/50-n-factorial/doc/answer.png -------------------------------------------------------------------------------- /Medium-Questions/50-n-factorial/doc/question.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/50-n-factorial/doc/question.png -------------------------------------------------------------------------------- /Medium-Questions/50-n-factorial/python/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | 4 | def factorial(n): 5 | """ 6 | this function get number and return factorial of it 7 | """ 8 | if n == 1: 9 | return 1 10 | return n * factorial(n - 1) 11 | 12 | 13 | def main(): 14 | n = input("Enter a Number: ") 15 | try: 16 | n = int(n) 17 | except ValueError: 18 | sys.exit("Input Must be Integer") 19 | 20 | # iterate from 1 to n (Number that User enter) 21 | for i in range(1, n+1): 22 | # check value of factorial is equal to n or not 23 | if factorial(i) == n: 24 | print(f"Factorial of {i} is {n}") 25 | 26 | if __name__ == '__main__': 27 | main() -------------------------------------------------------------------------------- /Medium-Questions/50-n-factorial/readme.md: -------------------------------------------------------------------------------- 1 | # کارشناسی نرم افزار واحد پسرانه شماره یک یزد 2 | 3 | 4 | سوال: 5 | 6 | 7 | 8 | خروجی: 9 | 10 | -------------------------------------------------------------------------------- /Medium-Questions/51-sum-of-factorial/doc/answer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/51-sum-of-factorial/doc/answer.png -------------------------------------------------------------------------------- /Medium-Questions/51-sum-of-factorial/doc/question.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/51-sum-of-factorial/doc/question.png -------------------------------------------------------------------------------- /Medium-Questions/51-sum-of-factorial/python/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | 4 | def factorial(n): 5 | """ 6 | this function get number and return factorial of it 7 | """ 8 | if n == 1: 9 | return 1 10 | return n * factorial(n - 1) 11 | 12 | 13 | def main(): 14 | n = input("Enter a Number: ") 15 | try: 16 | n = int(n) 17 | except ValueError: 18 | sys.exit("Input Must be Integer") 19 | 20 | result = 0 21 | # iterate from 1 to n (Number that User enter) 22 | for i in range(1, n+1): 23 | result += factorial(i) 24 | 25 | if i == (n): 26 | print(f"{i}!", end=" ") 27 | else: 28 | print(f"{i}!", end=" + ") 29 | 30 | print(f"= {result}") 31 | 32 | for i in range(1, n+1): 33 | if i == (n): 34 | print(f"{factorial(i)} ", end=" ") 35 | else: 36 | print(f"{factorial(i)} ", end=" + ") 37 | 38 | print(f"= {result}") 39 | 40 | 41 | if __name__ == '__main__': 42 | main() -------------------------------------------------------------------------------- /Medium-Questions/51-sum-of-factorial/readme.md: -------------------------------------------------------------------------------- 1 | # کارشناسی نرم افزار واحد پسرانه شماره یک یزد 2 | 3 | 4 | سوال: 5 | 6 | 7 | 8 | خروجی: 9 | 10 | -------------------------------------------------------------------------------- /Medium-Questions/52-div-of-factorial/doc/answer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/52-div-of-factorial/doc/answer.png -------------------------------------------------------------------------------- /Medium-Questions/52-div-of-factorial/doc/question.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/52-div-of-factorial/doc/question.png -------------------------------------------------------------------------------- /Medium-Questions/52-div-of-factorial/python/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | 4 | def factorial(n): 5 | """ 6 | this function get number and return factorial of it 7 | """ 8 | if n == 1: 9 | return 1 10 | return n * factorial(n - 1) 11 | 12 | 13 | def main(): 14 | n = input("Enter a Number: ") 15 | try: 16 | n = int(n) 17 | except ValueError: 18 | sys.exit("Input Must be Integer") 19 | 20 | result = 0 21 | # iterate from 1 to n (Number that User enter) 22 | for i in range(1, n+1): 23 | result += i / factorial(i) 24 | 25 | if i == (n): 26 | print(f"({i} / {i}!)", end=" ") 27 | else: 28 | print(f"({i} / {i}!)", end="\33[32m + \33[0m") 29 | 30 | print(f"\33[31m = \33[0m {result} ") 31 | 32 | for i in range(1, n+1): 33 | if i == (n): 34 | print(f"({i} / {factorial(i)})", end=" ") 35 | else: 36 | print(f"({i} / {factorial(i)})", end="\33[32m + \33[0m") 37 | 38 | print(f"\33[31m = \33[0m {result} ") 39 | 40 | if __name__ == '__main__': 41 | main() -------------------------------------------------------------------------------- /Medium-Questions/52-div-of-factorial/readme.md: -------------------------------------------------------------------------------- 1 | # کارشناسی نرم افزار واحد پسرانه شماره یک یزد 2 | 3 | 4 | سوال: 5 | 6 | 7 | 8 | خروجی: 9 | 10 | -------------------------------------------------------------------------------- /Medium-Questions/53-fibonacci-n's/doc/answer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/53-fibonacci-n's/doc/answer.png -------------------------------------------------------------------------------- /Medium-Questions/53-fibonacci-n's/doc/question.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/53-fibonacci-n's/doc/question.png -------------------------------------------------------------------------------- /Medium-Questions/53-fibonacci-n's/python/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | 4 | def fibonacci(n): 5 | """ 6 | this function get number and return fibonacci value of it 7 | """ 8 | a = 0 9 | b = 1 10 | c = 0 11 | for i in range(n): 12 | c = a + b 13 | a,b = b ,c 14 | 15 | return c 16 | 17 | 18 | def main(): 19 | n = input("Enter a Number: ") 20 | try: 21 | n = int(n) 22 | except ValueError: 23 | sys.exit("Input Must be Integer") 24 | 25 | print(f"{n}'s Number in Fibonacci Sequences is {fibonacci(n)}") 26 | 27 | 28 | 29 | if __name__ == '__main__': 30 | main() -------------------------------------------------------------------------------- /Medium-Questions/53-fibonacci-n's/readme.md: -------------------------------------------------------------------------------- 1 | # کارشناسی نرم افزار واحد پسرانه شماره یک یزد 2 | 3 | 4 | سوال: 5 | 6 | 7 | 8 | خروجی: 9 | 10 | -------------------------------------------------------------------------------- /Medium-Questions/54-fibonacci-m-and-n/doc/answer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/54-fibonacci-m-and-n/doc/answer.png -------------------------------------------------------------------------------- /Medium-Questions/54-fibonacci-m-and-n/doc/answer1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/54-fibonacci-m-and-n/doc/answer1.png -------------------------------------------------------------------------------- /Medium-Questions/54-fibonacci-m-and-n/doc/question.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/54-fibonacci-m-and-n/doc/question.png -------------------------------------------------------------------------------- /Medium-Questions/54-fibonacci-m-and-n/python/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | 4 | def fibonacci(m, n): 5 | """ 6 | this function get number and return fibonacci value of it 7 | """ 8 | a = 0 9 | b = 1 10 | c = 0 11 | result = [] 12 | for i in range(m): 13 | c = a + b 14 | a,b = b ,c 15 | result.append(c) 16 | if c > m+n: 17 | break 18 | 19 | if m in result: 20 | index = result.index(m) 21 | try: 22 | if result[index - 1] == n: 23 | print("\33[34mSequence is =>\33[0m ") 24 | for each in result: 25 | if each == n: 26 | print(f"\33[32m {each} \33[0m", end=" ") 27 | elif each == m: 28 | print(f"\33[32m {each} \33[0m", end=" ") 29 | else: 30 | print(each, end=" ") 31 | 32 | return True 33 | except IndexError: 34 | return False 35 | 36 | return False 37 | 38 | 39 | def main(): 40 | n = input("Enter N Number: ") 41 | try: 42 | n = int(n) 43 | except ValueError: 44 | sys.exit("Input Must be Integer") 45 | 46 | m = input("Enter M Number: ") 47 | try: 48 | m = int(m) 49 | except ValueError: 50 | sys.exit("Input Must be Integer") 51 | 52 | if m > n: 53 | pass 54 | else: 55 | # swap values 56 | n,m = m ,n 57 | 58 | res = fibonacci(m, n) 59 | if not res: 60 | print(res) 61 | 62 | if __name__ == '__main__': 63 | main() 64 | -------------------------------------------------------------------------------- /Medium-Questions/54-fibonacci-m-and-n/readme.md: -------------------------------------------------------------------------------- 1 | # کارشناسی نرم افزار واحد پسرانه شماره یک یزد 2 | 3 | 4 | سوال: 5 | 6 | 7 | 8 | خروجی: 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Medium-Questions/55-reverse-number/doc/answer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/55-reverse-number/doc/answer.png -------------------------------------------------------------------------------- /Medium-Questions/55-reverse-number/doc/question.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/55-reverse-number/doc/question.png -------------------------------------------------------------------------------- /Medium-Questions/55-reverse-number/python/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | 4 | 5 | def main(): 6 | n = input("Enter a Number sequences: ") 7 | if not n.isdigit(): 8 | sys.exit("Input Must a Number Sequences") 9 | # reverse str input 10 | n = n[::-1] 11 | 12 | # convert str input to int 13 | print(f"\nAnswer is => {int(n)} and answer Type is {type(int(n))}\n") 14 | 15 | 16 | if __name__ == '__main__': 17 | main() -------------------------------------------------------------------------------- /Medium-Questions/55-reverse-number/readme.md: -------------------------------------------------------------------------------- 1 | # کارشناسی نرم افزار واحد پسرانه شماره یک یزد 2 | 3 | 4 | سوال: 5 | 6 | 7 | 8 | خروجی: 9 | 10 | 11 | -------------------------------------------------------------------------------- /Medium-Questions/56-bin-to-8-10-16/doc/answer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/56-bin-to-8-10-16/doc/answer.png -------------------------------------------------------------------------------- /Medium-Questions/56-bin-to-8-10-16/doc/question.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/56-bin-to-8-10-16/doc/question.png -------------------------------------------------------------------------------- /Medium-Questions/56-bin-to-8-10-16/python/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | 4 | 5 | def main(): 6 | n = input("Enter a binary Number: ") 7 | m = n 8 | # convert str to int 9 | try: 10 | n = int(n, base=2) 11 | except ValueError: 12 | sys.exit("invalid input") 13 | 14 | print(f"\n-{m} in int<10> is {n}") 15 | print(f"-{m} in hex<16> is {hex(n)}") 16 | print(f"-{m} in oct<8> is {oct(n)}\n") 17 | 18 | if __name__ == '__main__': 19 | main() -------------------------------------------------------------------------------- /Medium-Questions/56-bin-to-8-10-16/readme.md: -------------------------------------------------------------------------------- 1 | # کارشناسی نرم افزار واحد پسرانه شماره یک یزد 2 | 3 | 4 | سوال: 5 | 6 | 7 | 8 | خروجی: 9 | 10 | 11 | -------------------------------------------------------------------------------- /Medium-Questions/57-long-long-numbers/doc/answer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/57-long-long-numbers/doc/answer.png -------------------------------------------------------------------------------- /Medium-Questions/57-long-long-numbers/doc/question.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/57-long-long-numbers/doc/question.png -------------------------------------------------------------------------------- /Medium-Questions/57-long-long-numbers/python/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | 4 | 5 | def main(): 6 | n = input("Enter a 30 digit Number: ") 7 | if len(n) != 30: 8 | sys.exit("number Must be 30 characters") 9 | 10 | m = input("Enter a 30 digit Number: ") 11 | if len(m) != 30: 12 | sys.exit("number Must be 30 characters") 13 | 14 | if not m.isdigit() or not n.isdigit: 15 | sys.exit("Input must be integer Number") 16 | 17 | # python is dynamic data type so this is not good for solving in python 18 | # but in other language like c c# and we should use correct type for variable to 19 | # calculate this otherwise it can be overflow 20 | print(int(m)+int(n)) 21 | 22 | if __name__ == '__main__': 23 | main() -------------------------------------------------------------------------------- /Medium-Questions/57-long-long-numbers/readme.md: -------------------------------------------------------------------------------- 1 | # کارشناسی نرم افزار واحد پسرانه شماره یک یزد 2 | 3 | 4 | سوال: 5 | 6 | 7 | 8 | خروجی: 9 | 10 | 11 | -------------------------------------------------------------------------------- /Medium-Questions/58-factiorial-value/doc/answer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/58-factiorial-value/doc/answer.png -------------------------------------------------------------------------------- /Medium-Questions/58-factiorial-value/doc/question.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/58-factiorial-value/doc/question.png -------------------------------------------------------------------------------- /Medium-Questions/58-factiorial-value/python/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | 4 | def factorial(n): 5 | if n == 1: 6 | return 1 7 | 8 | return n * factorial(n -1 ) 9 | 10 | def main(): 11 | n = input("Enter a Number: ") 12 | try: 13 | n = int(n) 14 | except ValueError: 15 | sys.exit("input must be integer ") 16 | 17 | print(f"Factorial value is : {factorial(n)}") 18 | if __name__ == '__main__': 19 | main() -------------------------------------------------------------------------------- /Medium-Questions/58-factiorial-value/readme.md: -------------------------------------------------------------------------------- 1 | # کارشناسی نرم افزار واحد پسرانه شماره یک یزد 2 | 3 | 4 | سوال: 5 | 6 | 7 | 8 | خروجی: 9 | 10 | 11 | -------------------------------------------------------------------------------- /Medium-Questions/59-min-max-avg/doc/answer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/59-min-max-avg/doc/answer.png -------------------------------------------------------------------------------- /Medium-Questions/59-min-max-avg/doc/question.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/59-min-max-avg/doc/question.png -------------------------------------------------------------------------------- /Medium-Questions/59-min-max-avg/python/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | 4 | def main(): 5 | n = input("Enter Number of round: ") 6 | try: 7 | n = int(n) 8 | except ValueError: 9 | sys.exit("input must be integer ") 10 | 11 | numbers = [] 12 | 13 | i = 0 14 | while True: 15 | if i == n: 16 | break 17 | temp = input(f"Enter Number \33[33m{i+1}\33[0m: ") 18 | 19 | try: 20 | temp = float(temp) 21 | except ValueError: 22 | print("invalid input :(") 23 | continue 24 | else: 25 | numbers.append(temp) 26 | i += 1 27 | 28 | 29 | print(f"\33[32mmaximum value is {max(numbers)}") 30 | print(f"minimum value is {min(numbers)}") 31 | print(f"average value is {sum(numbers) / len(numbers)} \33[0m") 32 | 33 | if __name__ == '__main__': 34 | main() 35 | -------------------------------------------------------------------------------- /Medium-Questions/59-min-max-avg/readme.md: -------------------------------------------------------------------------------- 1 | # کارشناسی نرم افزار واحد پسرانه شماره یک یزد 2 | 3 | 4 | سوال: 5 | 6 | 7 | 8 | خروجی: 9 | 10 | 11 | -------------------------------------------------------------------------------- /Medium-Questions/60-number-of-divisible/doc/answer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/60-number-of-divisible/doc/answer.png -------------------------------------------------------------------------------- /Medium-Questions/60-number-of-divisible/doc/question.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/60-number-of-divisible/doc/question.png -------------------------------------------------------------------------------- /Medium-Questions/60-number-of-divisible/python/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | 4 | def get_maqsom(n): 5 | result = [] 6 | for i in range(1, 10000): 7 | counter = 0 8 | for j in range(1, int(i / 2) + 1): 9 | if i % j == 0: 10 | counter += 1 11 | if counter == n: 12 | result.append(i) 13 | if counter > n: 14 | if i in result: 15 | result.remove(i) 16 | 17 | return result 18 | 19 | 20 | 21 | def main(): 22 | n = input("Enter Number of divisible: ") 23 | try: 24 | n = int(n) 25 | except ValueError: 26 | sys.exit("input must be integer ") 27 | 28 | result = get_maqsom(n) 29 | for each in result: 30 | print(each, end=" ") 31 | 32 | if __name__ == '__main__': 33 | main() -------------------------------------------------------------------------------- /Medium-Questions/60-number-of-divisible/readme.md: -------------------------------------------------------------------------------- 1 | # کارشناسی نرم افزار واحد پسرانه شماره یک یزد 2 | 3 | 4 | سوال: 5 | 6 | 7 | 8 | خروجی: 9 | 10 | 11 | -------------------------------------------------------------------------------- /Medium-Questions/61-union/doc/answer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/61-union/doc/answer.png -------------------------------------------------------------------------------- /Medium-Questions/61-union/doc/question.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/61-union/doc/question.png -------------------------------------------------------------------------------- /Medium-Questions/61-union/python/main.py: -------------------------------------------------------------------------------- 1 | import os, sys 2 | 3 | 4 | def get_maqsom(n): 5 | maqsom = set() 6 | for i in range(1, n+1): 7 | if n % i == 0: 8 | maqsom.add(i) 9 | return maqsom 10 | 11 | 12 | def main(): 13 | n = input("Enter First Number: ") 14 | m = input("Enter Second Number: ") 15 | try: 16 | n = int(n) 17 | m = int(m) 18 | except ValueError: 19 | sys.exit("Input Must be Integer") 20 | 21 | n_maq = get_maqsom(n) 22 | m_maq = get_maqsom(m) 23 | 24 | 25 | # print union of between to sets 26 | print(n_maq & m_maq) 27 | 28 | 29 | 30 | 31 | if __name__ == "__main__": 32 | main() -------------------------------------------------------------------------------- /Medium-Questions/61-union/readme.md: -------------------------------------------------------------------------------- 1 | # کارشناسی نرم افزار واحد پسرانه شماره یک یزد 2 | 3 | 4 | سوال: 5 | 6 | 7 | 8 | خروجی: 9 | 10 | 11 | -------------------------------------------------------------------------------- /Medium-Questions/62-a-div-b and c-div-d/doc/answer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/62-a-div-b and c-div-d/doc/answer.png -------------------------------------------------------------------------------- /Medium-Questions/62-a-div-b and c-div-d/doc/question.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/62-a-div-b and c-div-d/doc/question.png -------------------------------------------------------------------------------- /Medium-Questions/62-a-div-b and c-div-d/python/main.py: -------------------------------------------------------------------------------- 1 | import os, sys 2 | 3 | def main(): 4 | n = input("Enter a/b : ") 5 | m = input("Enter d/c : ") 6 | try: 7 | 8 | a = (n.strip().split("/"))[0] 9 | b = (n.strip().split("/"))[-1] 10 | d = (m.strip().split("/"))[0] 11 | c = (m.strip().split("/"))[-1] 12 | 13 | a = int(a) 14 | b = int(b) 15 | d = int(d) 16 | c = int(c) 17 | 18 | print(round(a//b) / round(d//c)) 19 | except (ValueError, IndexError): 20 | sys.exit("Input Must be Integer") 21 | 22 | 23 | if __name__ == "__main__": 24 | main() -------------------------------------------------------------------------------- /Medium-Questions/62-a-div-b and c-div-d/readme.md: -------------------------------------------------------------------------------- 1 | # کارشناسی نرم افزار واحد پسرانه شماره یک یزد 2 | 3 | 4 | سوال: 5 | 6 | 7 | 8 | خروجی: 9 | 10 | 11 | -------------------------------------------------------------------------------- /Medium-Questions/63-find-x/doc/answer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/63-find-x/doc/answer.png -------------------------------------------------------------------------------- /Medium-Questions/63-find-x/doc/question.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/63-find-x/doc/question.png -------------------------------------------------------------------------------- /Medium-Questions/63-find-x/python/main.py: -------------------------------------------------------------------------------- 1 | import os, sys 2 | 3 | # t = 137486 x 225 4 | 5 | 6 | def main(): 7 | for x in range(1,10): 8 | if int(f"137486{x}225") % 3 == 0: 9 | print(x, end=" - ") 10 | 11 | 12 | if __name__ == "__main__": 13 | main() 14 | -------------------------------------------------------------------------------- /Medium-Questions/63-find-x/readme.md: -------------------------------------------------------------------------------- 1 | # کارشناسی نرم افزار واحد پسرانه شماره یک یزد 2 | 3 | 4 | سوال: 5 | 6 | 7 | 8 | خروجی: 9 | 10 | 11 | -------------------------------------------------------------------------------- /Medium-Questions/64-find-another-x/doc/answer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/64-find-another-x/doc/answer.png -------------------------------------------------------------------------------- /Medium-Questions/64-find-another-x/doc/question.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/64-find-another-x/doc/question.png -------------------------------------------------------------------------------- /Medium-Questions/64-find-another-x/python/main.py: -------------------------------------------------------------------------------- 1 | import os, sys 2 | 3 | # t = 137486 x 225 4 | 5 | 6 | def main(): 7 | for x in range(1,10): 8 | if int(f"137486{x}225") % 7 == 0: 9 | print(x, end=" - ") 10 | 11 | if __name__ == "__main__": 12 | main() 13 | -------------------------------------------------------------------------------- /Medium-Questions/64-find-another-x/readme.md: -------------------------------------------------------------------------------- 1 | # کارشناسی نرم افزار واحد پسرانه شماره یک یزد 2 | 3 | 4 | سوال: 5 | 6 | 7 | 8 | خروجی: 9 | 10 | 11 | -------------------------------------------------------------------------------- /Medium-Questions/65-1000-prime-number/doc/question.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/65-1000-prime-number/doc/question.png -------------------------------------------------------------------------------- /Medium-Questions/65-1000-prime-number/python/main.py: -------------------------------------------------------------------------------- 1 | import os, sys 2 | 3 | # x ^ 34 - 9 4 | 5 | def is_prime(n): 6 | for i in range(2, int(n / 2) +1): 7 | if n % i == 0 : 8 | return False 9 | return True 10 | 11 | def main(): 12 | primes = [] 13 | for x in range(1, 1000): 14 | target = x ** 34 - 9 15 | temp = f"{x} ^34 - 9" 16 | if is_prime(target): 17 | primes.append(temp) 18 | print(primes) 19 | 20 | if __name__ == "__main__": 21 | main() -------------------------------------------------------------------------------- /Medium-Questions/65-1000-prime-number/readme.md: -------------------------------------------------------------------------------- 1 | # کارشناسی نرم افزار واحد پسرانه شماره یک یزد 2 | 3 | 4 | سوال: 5 | 6 | 7 | 8 | خروجی: 9 | 10 | 11 | -------------------------------------------------------------------------------- /Medium-Questions/66-median/doc/answer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/66-median/doc/answer.png -------------------------------------------------------------------------------- /Medium-Questions/66-median/doc/question.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/66-median/doc/question.png -------------------------------------------------------------------------------- /Medium-Questions/66-median/python/main.py: -------------------------------------------------------------------------------- 1 | import os, sys 2 | 3 | 4 | 5 | def main(): 6 | 7 | n = input("enter length of numbers: ") 8 | try: 9 | n = int(n) 10 | except ValueError: 11 | sys.exit("Input must be integer ") 12 | 13 | 14 | counter = 0 15 | numbers = [] 16 | 17 | while n > counter: 18 | m = input(f"Enter Number {counter + 1}: ") 19 | try: 20 | m = int(m) 21 | except ValueError: 22 | print(" \33[33m invalid input \33[0m") 23 | continue 24 | else: 25 | numbers.append(m) 26 | counter +=1 27 | 28 | # sort numbers 29 | numbers.sort() 30 | 31 | # if length of input is even 32 | if len(numbers) % 2 == 0: 33 | # like [1, 2, 3, 4, 5, 6] 34 | # [1, 2, <3, 4,> 5, 6] middle in this case in 3 and 4 35 | # we should get average of this two numbers For Median 36 | 37 | b, a = numbers[round(len(numbers) / 2) - 1], numbers[round(len(numbers) / 2)] 38 | print(sum((a,b)) / 2) 39 | 40 | # if length if input is prime number 41 | # we just slice it to middele and round it to up 42 | # like [1, 2, 3, <4> 5, 6, 7] in this case middle is 4 43 | # for getting 4 we should first get length of list and divided by 2 44 | # that give us 3.5 and we round it to up and we got 4 45 | 46 | elif len(numbers) % 2 != 0: 47 | # because in array we count from 0 we should increment 1 from result 48 | print(numbers[round(len(numbers) / 2) - 1]) 49 | 50 | 51 | if __name__ == "__main__": 52 | main() -------------------------------------------------------------------------------- /Medium-Questions/66-median/readme.md: -------------------------------------------------------------------------------- 1 | # کارشناسی نرم افزار واحد پسرانه شماره یک یزد 2 | 3 | 4 | سوال: 5 | 6 | 7 | 8 | خروجی: 9 | 10 | 11 | -------------------------------------------------------------------------------- /Medium-Questions/67-prime-2-n/Python/main.py: -------------------------------------------------------------------------------- 1 | import os,sys 2 | 3 | 4 | def get_factor(n): 5 | """ 6 | this function take an number and return factors of that number 7 | """ 8 | maqsom = [] 9 | for i in range(1, int(round(n / 2)+ 1)): 10 | if n % i == 0: 11 | maqsom.append(i) 12 | 13 | if 1 not in maqsom: 14 | maqsom.append(1) 15 | 16 | if n not in maqsom: 17 | maqsom.append(n) 18 | 19 | return maqsom 20 | 21 | 22 | def main(): 23 | number = int(input("Enter a Number: ")) 24 | 25 | target_number = 0 26 | len_number = 0 27 | 28 | # iterate from 1 to n 29 | for each in range(1, number + 1): 30 | # get each number factors 31 | n_maq = get_factor(each) 32 | # print factor of each number 33 | print(f"{each}: {n_maq}") 34 | 35 | # keep track of number that have biggest factors 36 | if len(n_maq) > len_number: 37 | target_number = each 38 | len_number = len(n_maq) 39 | 40 | 41 | # print rsuallt 42 | print(f"Number \33[32m{target_number}\33[0m have \33[32m{len_number}\33[0m factors") 43 | 44 | 45 | if __name__ == "__main__": 46 | main() 47 | -------------------------------------------------------------------------------- /Medium-Questions/67-prime-2-n/README.md: -------------------------------------------------------------------------------- 1 | # کارشناسی نرم افزار روزانه یزد 2 | 3 | 4 | 5 | سوال: 6 | 7 | 8 | 9 | 10 | 11 | خروجی: 12 | 13 | -------------------------------------------------------------------------------- /Medium-Questions/67-prime-2-n/docs/answer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/67-prime-2-n/docs/answer.png -------------------------------------------------------------------------------- /Medium-Questions/67-prime-2-n/docs/question.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/67-prime-2-n/docs/question.jpg -------------------------------------------------------------------------------- /Medium-Questions/68-biggest-prime-2-n-into-n/Python/main.py: -------------------------------------------------------------------------------- 1 | import os,sys 2 | 3 | 4 | 5 | def is_prime(n): 6 | """ 7 | this function take an number and 8 | check number is prime number or not 9 | """ 10 | for each in range(2,n): 11 | if n % each == 0: 12 | return False 13 | return True 14 | 15 | 16 | 17 | def get_prime_factor(n): 18 | """ 19 | this function take an number 20 | and factors of that number 21 | """ 22 | maqsom = [] 23 | for i in range(2, int(round(n / 2)+ 1)): 24 | if n % i == 0: 25 | maqsom.append(i) 26 | maqsom = [x for x in maqsom if is_prime(x)] 27 | 28 | return maqsom 29 | 30 | 31 | 32 | def main(): 33 | number = int(input("Enter a Number: ")) 34 | 35 | biggest = 0 36 | big_n = 0 37 | 38 | # iterate over 1 to n 39 | for each in range(2, number + 1): 40 | 41 | # get each number factors 42 | n_maq = get_prime_factor(each) 43 | 44 | # print factor of each number 45 | print(f"{each}: {n_maq}") 46 | 47 | if len(n_maq) >= biggest: 48 | big_n = each 49 | biggest = len(n_maq) 50 | 51 | print(f"Number {big_n} with {biggest} prime factor") 52 | 53 | 54 | if __name__ == "__main__": 55 | main() 56 | -------------------------------------------------------------------------------- /Medium-Questions/68-biggest-prime-2-n-into-n/README.md: -------------------------------------------------------------------------------- 1 | # کارشناسی نرم افزار روزانه یزد 2 | 3 | برنامه ای بنویسید که یک عدد دریافت کرده و از 1 تا آن عدد، آن عددی که بزرگترین فاکتور اول را دارد نمایش دهد 4 | -------------------------------------------------------------------------------- /Medium-Questions/69-Reverse-Numbers/C#/Reverse-numbers.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Reverse_Numbers 8 | { 9 | internal class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | // way One - 14 | int height = 8; 15 | for (int i = 0; i < height; i++) 16 | { 17 | for (int j = 0; j < height-i; j++) 18 | { 19 | Console.Write(i+1 + " "); 20 | } 21 | Console.WriteLine(); 22 | } 23 | Console.ReadKey(); 24 | 25 | // way two - 26 | // int height = 8; 27 | // int counter = height; 28 | // for (int i = 0; i < height; i++) 29 | // { 30 | // for (int j = 0; j < counter; j++) 31 | // { 32 | // Console.Write(i+1 + " "); 33 | // } 34 | // counter--; 35 | // Console.WriteLine(); 36 | // } 37 | // Console.ReadKey(); 38 | 39 | 40 | } 41 | } 42 | } 43 | 44 | -------------------------------------------------------------------------------- /Medium-Questions/69-Reverse-Numbers/Python/app.py: -------------------------------------------------------------------------------- 1 | height = 9 2 | 3 | for i in range(0,height): 4 | for j in range(0, height-i): 5 | print(i+1 ," ", end="") 6 | print("") -------------------------------------------------------------------------------- /Medium-Questions/69-Reverse-Numbers/README.md: -------------------------------------------------------------------------------- 1 | ## برنامه سازی پیشرفته (دانشکده شهید بهشتی کرج) 2 | 3 | 4 | برنامه ای بنویسید که خروجی زیر را نمایش دهد 5 | 6 | 7 | 8 | خروجی: 9 | 10 | 11 | -------------------------------------------------------------------------------- /Medium-Questions/69-Reverse-Numbers/docs/answer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/69-Reverse-Numbers/docs/answer.png -------------------------------------------------------------------------------- /Medium-Questions/69-Reverse-Numbers/docs/question.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/69-Reverse-Numbers/docs/question.jpg -------------------------------------------------------------------------------- /Medium-Questions/69-Reverse-String-input/Python/app.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | 4 | def main(): 5 | x = input("Enter Input: ") 6 | x = x.split(" ") 7 | x.reverse() 8 | answer = " ".join(x) 9 | print(answer) 10 | 11 | 12 | if __name__ == "__main__": 13 | main() -------------------------------------------------------------------------------- /Medium-Questions/69-Reverse-String-input/README.md: -------------------------------------------------------------------------------- 1 | 2 | محدودیت زمان: ۰.۵ ثانیه 3 | محدودیت حافظه: ۲۵۶ مگابایت 4 | در این سوال باید برنامه‌ای بنویسید که 5 | n کلمه از ورودی دریافت کرده و ترتیب کلمات آن را برعکس کند و در خروجی چاپ کند. 6 | 7 | ورودی 8 | در سطر اول ورودی 9 | 10 | n می‌آید که نمایانگر تعداد کلمات است. در سطر دوم ورودی 11 | 12 | n کلمه می‌آید که با فاصله از هم جدا شده‌اند. کاراکترهای به کار رفته در این کلمات حروف کوچک و بزرگ انگلیسی می‌باشند. مجموع طول تمام کلمه‌ها از 1000 کاراکتر بیشتر نیست. 13 | 14 | 1≤ n ≤100 15 | 16 | خروجی 17 | در تنها سطر خروجی کلمات داده شده را به ترتیب برعکس ورودی چاپ کنید. دقت کنید که کوچک و بزرگ بودن حروف خروجی باید مانند حروف ورودی باشد. 18 | 19 | مثال 20 | ورودی نمونه 21 | 11 22 | I Am from Iran it iS rainy and i like rain 23 | Plain text 24 | خروجی نمونه 25 | rain like i and rainy iS it Iran from Am I -------------------------------------------------------------------------------- /Medium-Questions/70-Mult-Table/Python/app.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | def get_int(message:str) -> int: 4 | while True: 5 | x = input(message) 6 | try: 7 | x = int(x) 8 | except ValueError: 9 | continue 10 | else: 11 | return x 12 | 13 | 14 | def main(): 15 | x = get_int("enter number: ") 16 | for i in range(1, x+1): 17 | for j in range(1, x+1): 18 | print(j*i, end=" ") 19 | print("") 20 | 21 | 22 | 23 | if __name__ == "__main__": 24 | main() -------------------------------------------------------------------------------- /Medium-Questions/70-Mult-Table/README.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Medium-Questions/70-Mult-Table/doc/question.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/70-Mult-Table/doc/question.png -------------------------------------------------------------------------------- /Medium-Questions/71-Pascals-triangle/Python/app.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | 4 | def getBaseTriangle(size) -> list: 5 | n = [None] * size 6 | 7 | if len(n) >= 3: 8 | n[0] = 1 9 | n[-1] = 1 10 | 11 | if len(n) == 1: 12 | n[0] = 1 13 | 14 | elif len(n) == 2: 15 | n[0], n[1] = 1, 1 16 | 17 | return n 18 | 19 | 20 | 21 | def makeThisLevel(level): 22 | response = str(11 ** level) 23 | temp = [] 24 | for each in response: 25 | temp.append(each) 26 | return temp 27 | 28 | 29 | 30 | 31 | def main(): 32 | global data 33 | data = [] 34 | 35 | while True: 36 | try: 37 | x = int(input("level: ")) 38 | except ValueError: 39 | continue 40 | else: 41 | break 42 | plevel = 0 43 | for each in range(x): 44 | data.append(makeThisLevel(each)) 45 | 46 | max_len = len(data[-1]) 47 | for index, i in enumerate(data): 48 | space = max_len - len(i) 49 | print(f"[{index}]", end=" ") 50 | print(" " * ((space // 2 +1 )), "".join(i), " " * (space //2 +1), end="") 51 | print("") 52 | 53 | # normal print 54 | # for each in data: 55 | # print(" ".join(each)) 56 | 57 | 58 | 59 | if __name__ == "__main__": 60 | main() -------------------------------------------------------------------------------- /Medium-Questions/71-Pascals-triangle/README.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Medium-Questions/71-Pascals-triangle/doc/question.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/71-Pascals-triangle/doc/question.png -------------------------------------------------------------------------------- /Medium-Questions/72-level-2-equations/JavaScript/app.js: -------------------------------------------------------------------------------- 1 | 2 | function Exit() { 3 | throw Error("Exit Dudo"); 4 | 5 | } 6 | 7 | 8 | function EquationTwo(a, b, c) { 9 | this.a = 0; 10 | this.b = 0; 11 | this.c = 0; 12 | this.values = { "a": 0, "b": 0, "c": 0, "delta": 0, "answer": 0 }; 13 | 14 | 15 | this.get_a_b_c = () => { 16 | let value = ["a", "b", "c"]; 17 | function getFloat(message) { 18 | while (true) { 19 | let tmp = prompt(message); 20 | if (tmp === "q") { 21 | Exit() 22 | } 23 | let v = parseFloat(tmp); 24 | switch (v) { 25 | 26 | case !v: 27 | continue 28 | case 0: 29 | return v; 30 | default: 31 | if (v >= -100) { 32 | if (v <= 100) { 33 | return v; 34 | } 35 | } 36 | 37 | } 38 | } 39 | } 40 | value.forEach(e => { 41 | let v = getFloat(`Enter ${e}: `); 42 | this.values[e] = v; 43 | }) 44 | } 45 | 46 | 47 | 48 | this.calculateDelta = () => { 49 | 50 | /* 51 | delta = (b ** 2) - (4 * a * c) 52 | b ^ 2 - 4ac 53 | */ 54 | let a = this.values["a"]; 55 | let b = this.values["b"]; 56 | let c = this.values["c"]; 57 | if (a !== 0 && b !== 0) { 58 | this.values["delta"] = (b ** 2) - (4 * a * c); 59 | } 60 | else { 61 | alert("IMPOSSIBLE"); 62 | Exit(); 63 | 64 | } 65 | } 66 | 67 | 68 | 69 | this.print_answer = () => { 70 | 71 | let a = this.values["a"]; 72 | let b = this.values["b"]; 73 | let c = this.values["c"]; 74 | let delta = this.values["delta"]; 75 | 76 | if (delta > 0) { 77 | 78 | /* 79 | - (b) + (delta) ** 0.5 / 2a 80 | - (b) - (delta) ** 0.5 / 2a 81 | */ 82 | x1 = (-b + (delta ** 0.5)) / (2 * a) 83 | x2 = (-b - (delta ** 0.5)) / (2 * a) 84 | 85 | alert(`X1: ${(x1).toFixed(3)}`) 86 | alert(`X2: ${(x2).toFixed(3)}`) 87 | Exit() 88 | } 89 | else if (delta == 0) { 90 | 91 | x = -b / (2 * a) 92 | alert(`X: ${(x).toFixed(3)}`) 93 | Exit() 94 | } 95 | else { 96 | 97 | alert("IMPOSSIBLE") 98 | Exit() 99 | } 100 | 101 | } 102 | } 103 | 104 | 105 | function main() { 106 | let e2 = new EquationTwo() 107 | e2.get_a_b_c() 108 | e2.calculateDelta() 109 | e2.print_answer() 110 | } 111 | 112 | 113 | main() -------------------------------------------------------------------------------- /Medium-Questions/72-level-2-equations/JavaScript/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Document 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Medium-Questions/72-level-2-equations/Python/app.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import math 4 | 5 | 6 | class EquationTwo: 7 | def __init__(self): 8 | self.values = {"a": 0, "b": 0, "c": 0, "delta": 0, "answer": 0} 9 | 10 | def get_a_b_c(self): 11 | """This Method Get a,b,c for user""" 12 | 13 | def get_float(message: str) -> int: 14 | """Get Integer Value From user 15 | Only Int""" 16 | while True: 17 | x = input(message) 18 | try: 19 | x = float(x) 20 | if x >= -100 and x <= 100: # −100≤a,b,c≤100 21 | return x 22 | else: 23 | continue 24 | except ValueError: 25 | print("Invalid Value :(\n") 26 | continue 27 | 28 | for i in ["a", "b", "c"]: 29 | self.values[i] = get_float(f"Enter {i}:") 30 | 31 | def calculateDelta(self): 32 | """ 33 | delta = (b**2)-(4*a*c) 34 | b^2-4ac 35 | """ 36 | a, b, c = self.values["a"], self.values["b"], self.values["c"] 37 | if a != 0 and b != 0: 38 | self.values["delta"] = (b ** 2) - (4 * a * c) 39 | else: 40 | print("IMPOSSIBLE") 41 | sys.exit(0) 42 | 43 | def print_answer(self): 44 | a, b, c, delta = self.values["a"], self.values["b"], self.values["c"], self.values["delta"] 45 | print(f"Delta: {delta}") 46 | if delta > 0: 47 | """ 48 | -(b)+(delta)**0.5/2a 49 | -(b)-(delta)**0.5/2a 50 | """ 51 | x1 = (-b + (delta ** 0.5)) / (2 * a) 52 | x2 = (-b - (delta ** 0.5)) / (2 * a) 53 | 54 | print(f"X1: {round(x1, 3)}") 55 | print(f"X2: {round(x2, 3)}") 56 | sys.exit(0) 57 | elif delta == 0: 58 | x = -b / (2 * a) 59 | print(f"X: {round(x, 3)}") 60 | sys.exit(0) 61 | else: 62 | print("IMPOSSIBLE") 63 | sys.exit(0) 64 | 65 | 66 | def main(): 67 | e = EquationTwo() 68 | e.get_a_b_c() 69 | e.calculateDelta() 70 | e.print_answer() 71 | 72 | 73 | if __name__ == "__main__": 74 | main() 75 | -------------------------------------------------------------------------------- /Medium-Questions/72-level-2-equations/README.md: -------------------------------------------------------------------------------- 1 | سوال: 2 | 3 | 4 | 5 | https://quera.org/problemset/294/ 6 | 7 | -------------------------------------------------------------------------------- /Medium-Questions/72-level-2-equations/docs/question.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/72-level-2-equations/docs/question.png -------------------------------------------------------------------------------- /Medium-Questions/73-distinct-numbers/Python/app.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | """ 4 | 1 <= n <= 2.10^5 5 | 1 <= x_i <= 10^9 6 | """ 7 | 8 | 9 | def main(): 10 | n = int(input()) 11 | 12 | # if (n < 1 or n >= (2 * (10 ** 5))): # n 13 | # sys.exit("Invalid input n") 14 | 15 | numbers = input() 16 | numbers = numbers.split() 17 | 18 | if len(numbers) != n: 19 | sys.exit("length of numbers must be equal to n") 20 | 21 | # for each in numbers: 22 | # each = int(each) 23 | # if (1 >= each or each >= 10**9): 24 | # sys.exit("Invalid input x must be between 1 and 10**9") 25 | 26 | 27 | numbers_bank = set(numbers) 28 | # set removes duplicates numbers automatically 29 | print(len(numbers_bank)) 30 | 31 | 32 | if __name__ == '__main__': 33 | main() 34 | -------------------------------------------------------------------------------- /Medium-Questions/73-distinct-numbers/README.md: -------------------------------------------------------------------------------- 1 | You are given a list of n integers, and your task is to calculate the number of distinct values in the list. 2 | Input 3 | The first input line has an integer n: the number of values. 4 | The second line has n integers x_1,x_2,\dots,x_n. 5 | Output 6 | Print one integers: the number of distinct values. 7 | 8 | 9 | https://cses.fi/problemset/task/1621 10 | 11 | 12 | -------------------------------------------------------------------------------- /Medium-Questions/73-distinct-numbers/doc/quiz.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/73-distinct-numbers/doc/quiz.png -------------------------------------------------------------------------------- /Medium-Questions/74-JackSparo/Python/app.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | """ 4 | https://quera.org/problemset/234249 5 | """ 6 | 7 | def get_int(msg=""): 8 | x = input(msg) 9 | if not x.isdigit(): 10 | sys.exit("input must be a number") 11 | 12 | return int(x) 13 | 14 | def main(): 15 | numbers = input().split() 16 | if len(numbers) != 7 : 17 | sys.exit("length of numbers must be 7") 18 | 19 | 20 | for index,value in enumerate(numbers): 21 | if not value.isdigit(): 22 | sys.exit("number must be a digit") 23 | numbers[index] = int(value) 24 | 25 | n = get_int() 26 | if n > 7 or n < 1: 27 | sys.exit("invalid number, n must between 1 and 7") 28 | 29 | 30 | index = numbers.index(n) 31 | len_before = len(numbers) 32 | numbers = numbers[:index-1] 33 | 34 | print((len_before-len(numbers))-1) 35 | 36 | 37 | if __name__ == '__main__': 38 | main() -------------------------------------------------------------------------------- /Medium-Questions/74-JackSparo/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | https://quera.org/problemset/234249 5 | -------------------------------------------------------------------------------- /Medium-Questions/74-JackSparo/doc/quiz.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/74-JackSparo/doc/quiz.png -------------------------------------------------------------------------------- /Medium-Questions/75-Delta-Logo-D/Python/app.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | 4 | """ 5 | dimensions = 𝑛×(2𝑛−1) 6 | each line = 2*n-1 7 | https://quera.org/problemset/220669 8 | 9 | dimensions: 8*(2*n-1) 10 | max = 8 * 2 - 1 11 | in: 8 12 | .......D....... 13 | ......D.D...... 14 | .....D...D..... 15 | ....D.....D.... 16 | ...D.......D... 17 | ..D.........D.. 18 | .D...........D. 19 | D.D.D.D.D.D.D.D 20 | 21 | in: 3 22 | ..D.. 23 | .D.D. 24 | D.D.D 25 | 26 | """ 27 | 28 | 29 | def main(): 30 | n = int(input("")) 31 | if n > 20 or n < 3: 32 | sys.exit("Invalid n") 33 | 34 | M_CHAR = (n * 2) - 1 35 | 36 | for i in range(n): 37 | 38 | for before in range(i, (M_CHAR//2)): # before 39 | print(".", end="") 40 | 41 | for inner in range((M_CHAR//2)-i, n): 42 | if i == n-1: 43 | if inner == 0: 44 | print("D.", end="") 45 | elif inner == n-1: 46 | print("D", end="") 47 | else: 48 | print("D.", end="") 49 | else: 50 | if inner == (M_CHAR//2)-i and i != 0: 51 | print("D.", end="") 52 | elif inner == n-1: 53 | print("D", end="") 54 | else: 55 | if inner != 0: 56 | for dot in range(2): 57 | print(".", end="") 58 | else: 59 | print(".", end="") 60 | 61 | for after in range(i, (M_CHAR//2)): # after 62 | print(".", end="") 63 | 64 | print() 65 | 66 | 67 | if __name__ == '__main__': 68 | main() 69 | -------------------------------------------------------------------------------- /Medium-Questions/75-Delta-Logo-D/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | https://quera.org/problemset/220669 -------------------------------------------------------------------------------- /Medium-Questions/75-Delta-Logo-D/doc/quiz.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/75-Delta-Logo-D/doc/quiz.png -------------------------------------------------------------------------------- /Medium-Questions/76-sticks-length/Python/app.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | def main(): 4 | n = int(input()) 5 | sticks = input().split() 6 | if len(sticks) != n: 7 | sys.exit("Invalid n") 8 | 9 | sticks = [int(each) for each in sticks] 10 | sticks.sort() 11 | medianINDEX = len(sticks)//2 12 | median = sticks[medianINDEX] 13 | cost = 0 14 | for index, value in enumerate(sticks): 15 | if index == medianINDEX: 16 | continue 17 | cost += abs(value-median) 18 | 19 | print(cost) 20 | 21 | if __name__ == '__main__': 22 | main() -------------------------------------------------------------------------------- /Medium-Questions/76-sticks-length/README.md: -------------------------------------------------------------------------------- 1 | Time limit: 1.00 s 2 | Memory limit: 512 MB 3 | 4 | 5 | 6 | There are n sticks with some lengths. Your task is to modify the sticks so that each stick has the same length. 7 | You can either lengthen and shorten each stick. Both operations cost x where x is the difference between the new and original length. 8 | What is the minimum total cost? 9 | Input 10 | The first input line contains an integer n: the number of sticks. 11 | Then there are n integers: p_1,p_2,\ldots,p_n: the lengths of the sticks. 12 | Output 13 | Print one integer: the minimum total cost. 14 | Constraints 15 | 16 | 1 \le n \le 2 \cdot 10^5 17 | 1 \le p_i \le 10^9 18 | 19 | Example 20 | Input: 21 | 5 22 | 2 3 1 5 2 23 | 24 | Output: 25 | 5 26 | 27 | 28 | https://cses.fi/problemset/task/1074/ -------------------------------------------------------------------------------- /Medium-Questions/77-song-length/Python/app.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | x = int(input()) 3 | songs = input().strip().split() 4 | 5 | previews_numbers = [] 6 | timer = 0 7 | max_sequence = 0 8 | 9 | for each in songs: 10 | if max_sequence < timer: 11 | max_sequence = timer 12 | if each in previews_numbers: 13 | timer = 0 14 | previews_numbers = [] 15 | previews_numbers.append(each) 16 | timer = 1 17 | else: 18 | timer += 1 19 | previews_numbers.append(each) 20 | else: 21 | if max_sequence < timer: 22 | max_sequence = timer 23 | 24 | print(max_sequence) 25 | 26 | 27 | # 2 3 4 5 2 10 9 8 6 1 28 | 29 | 30 | 31 | 32 | 33 | if __name__ == '__main__': 34 | main() -------------------------------------------------------------------------------- /Medium-Questions/77-song-length/README.md: -------------------------------------------------------------------------------- 1 | Time limit: 1.00 s 2 | Memory limit: 512 MB 3 | 4 | 5 | 6 | You are given a playlist of a radio station since its establishment. The playlist has a total of n songs. 7 | What is the longest sequence of successive songs where each song is unique? 8 | Input 9 | The first input line contains an integer n: the number of songs. 10 | The next line has n integers k_1,k_2,\ldots,k_n: the id number of each song. 11 | Output 12 | Print the length of the longest sequence of unique songs. 13 | Constraints 14 | 15 | 1 \le n \le 2 \cdot 10^5 16 | 1 \le k_i \le 10^9 17 | 18 | Example 19 | Input: 20 | 8 21 | 1 2 1 3 2 7 4 2 22 | 23 | Output: 24 | 5 -------------------------------------------------------------------------------- /Medium-Questions/77-song-length/tests/1.in: -------------------------------------------------------------------------------- 1 | 10 2 | 1 1 1 1 1 1 1 1 1 1 3 | -------------------------------------------------------------------------------- /Medium-Questions/77-song-length/tests/1.out: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /Medium-Questions/77-song-length/tests/10.out: -------------------------------------------------------------------------------- 1 | 65407 2 | -------------------------------------------------------------------------------- /Medium-Questions/77-song-length/tests/11.out: -------------------------------------------------------------------------------- 1 | 200000 2 | -------------------------------------------------------------------------------- /Medium-Questions/77-song-length/tests/12.out: -------------------------------------------------------------------------------- 1 | 200000 2 | -------------------------------------------------------------------------------- /Medium-Questions/77-song-length/tests/13.in: -------------------------------------------------------------------------------- 1 | 5 2 | 1 1 3 4 5 3 | -------------------------------------------------------------------------------- /Medium-Questions/77-song-length/tests/13.out: -------------------------------------------------------------------------------- 1 | 4 2 | -------------------------------------------------------------------------------- /Medium-Questions/77-song-length/tests/14.out: -------------------------------------------------------------------------------- 1 | 447 2 | -------------------------------------------------------------------------------- /Medium-Questions/77-song-length/tests/15.out: -------------------------------------------------------------------------------- 1 | 200000 2 | -------------------------------------------------------------------------------- /Medium-Questions/77-song-length/tests/16.in: -------------------------------------------------------------------------------- 1 | 10 2 | 2 3 4 5 2 10 9 8 6 1 3 | -------------------------------------------------------------------------------- /Medium-Questions/77-song-length/tests/16.out: -------------------------------------------------------------------------------- 1 | 9 2 | -------------------------------------------------------------------------------- /Medium-Questions/77-song-length/tests/17.out: -------------------------------------------------------------------------------- 1 | 199998 2 | -------------------------------------------------------------------------------- /Medium-Questions/77-song-length/tests/18.in: -------------------------------------------------------------------------------- 1 | 1 2 | 1000000000 3 | -------------------------------------------------------------------------------- /Medium-Questions/77-song-length/tests/18.out: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /Medium-Questions/77-song-length/tests/19.out: -------------------------------------------------------------------------------- 1 | 200000 2 | -------------------------------------------------------------------------------- /Medium-Questions/77-song-length/tests/2.in: -------------------------------------------------------------------------------- 1 | 10 2 | 2 2 1 1 2 1 2 1 2 1 3 | -------------------------------------------------------------------------------- /Medium-Questions/77-song-length/tests/2.out: -------------------------------------------------------------------------------- 1 | 2 2 | -------------------------------------------------------------------------------- /Medium-Questions/77-song-length/tests/20.out: -------------------------------------------------------------------------------- 1 | 87381 2 | -------------------------------------------------------------------------------- /Medium-Questions/77-song-length/tests/3.in: -------------------------------------------------------------------------------- 1 | 10 2 | 3 3 3 3 5 1 5 1 1 4 3 | -------------------------------------------------------------------------------- /Medium-Questions/77-song-length/tests/3.out: -------------------------------------------------------------------------------- 1 | 3 2 | -------------------------------------------------------------------------------- /Medium-Questions/77-song-length/tests/4.in: -------------------------------------------------------------------------------- 1 | 10 2 | 45 9 37 81 69 99 49 71 90 30 3 | -------------------------------------------------------------------------------- /Medium-Questions/77-song-length/tests/4.out: -------------------------------------------------------------------------------- 1 | 10 2 | -------------------------------------------------------------------------------- /Medium-Questions/77-song-length/tests/5.in: -------------------------------------------------------------------------------- 1 | 10 2 | 372869721 745347772 7844865 407111219 83020106 177963453 122424219 493937023 469468920 316110714 3 | -------------------------------------------------------------------------------- /Medium-Questions/77-song-length/tests/5.out: -------------------------------------------------------------------------------- 1 | 10 2 | -------------------------------------------------------------------------------- /Medium-Questions/77-song-length/tests/6.out: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /Medium-Questions/77-song-length/tests/7.out: -------------------------------------------------------------------------------- 1 | 10 2 | -------------------------------------------------------------------------------- /Medium-Questions/77-song-length/tests/8.out: -------------------------------------------------------------------------------- 1 | 148 2 | -------------------------------------------------------------------------------- /Medium-Questions/77-song-length/tests/9.out: -------------------------------------------------------------------------------- 1 | 3498 2 | -------------------------------------------------------------------------------- /Medium-Questions/78-DNA-Repetitions/Python/app.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | def main(): 4 | x = input().strip() 5 | repetitions = dict() 6 | 7 | previewsWord = x[1:] 8 | previewsCounter = 0 9 | repetitions[previewsWord] = previewsCounter 10 | 11 | 12 | for currentWord in x: 13 | 14 | if previewsWord == currentWord: # same as previous word 15 | previewsCounter += 1 16 | continue 17 | 18 | if previewsWord != currentWord: # new word in lit 19 | if repetitions[previewsWord] < previewsCounter: # check count of current word is grater than previous word counter 20 | repetitions[previewsWord] = previewsCounter 21 | 22 | previewsWord = currentWord 23 | previewsCounter = 1 24 | if previewsWord in repetitions: 25 | if repetitions[previewsWord] < previewsCounter: # check count of current word is grater than previous word counter 26 | repetitions[previewsWord] = previewsCounter 27 | else: 28 | previewsCounter = 1 29 | repetitions[previewsWord] = previewsCounter 30 | 31 | continue 32 | 33 | if repetitions[previewsWord] < previewsCounter: 34 | repetitions[previewsWord] = previewsCounter 35 | 36 | repetitions = [int(each) for each in repetitions.values()] 37 | repetitions.sort(reverse=True) 38 | print(repetitions[0]) 39 | 40 | 41 | if __name__ == '__main__': 42 | main() 43 | -------------------------------------------------------------------------------- /Medium-Questions/78-DNA-Repetitions/README.md: -------------------------------------------------------------------------------- 1 | Time limit: 1.00 s 2 | Memory limit: 512 MB 3 | 4 | 5 | 6 | You are given a DNA sequence: a string consisting of characters A, C, G, and T. Your task is to find the longest repetition in the sequence. This is a maximum-length substring containing only one type of character. 7 | Input 8 | The only input line contains a string of n characters. 9 | Output 10 | Print one integer: the length of the longest repetition. 11 | Constraints 12 | 13 | 1 \le n \le 10^6 14 | 15 | Example 16 | Input: 17 | ATTCGGGA 18 | 19 | Output: 20 | 3 21 | 22 | https://cses.fi/problemset/task/1069 -------------------------------------------------------------------------------- /Medium-Questions/79-safe-locker/Python/app.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | 4 | def get_int(): 5 | while True: 6 | x = input() 7 | try: 8 | x = int(x) 9 | return x 10 | except ValueError: 11 | continue 12 | 13 | 14 | def get_str(): 15 | while True: 16 | x = input() 17 | if x: 18 | return x 19 | continue 20 | 21 | 22 | def main(): 23 | key = get_str() 24 | length = get_int() 25 | words = [] 26 | 27 | max_key_index = 0 28 | longest_key = None 29 | for i in range(length): 30 | w = get_str() 31 | if key in w: 32 | 33 | if w.index(key) > max_key_index: 34 | longest_key = w 35 | max_key_index = w.index(key) 36 | 37 | words.append(w) 38 | 39 | max_key_index += 1 40 | for each in words: 41 | if key in each: 42 | if each.index(key)+1 < max_key_index: 43 | gap = max_key_index - (each.index(key)+1) 44 | print(("*" * gap) + each) 45 | else: 46 | print(each) 47 | else: 48 | print(each) 49 | 50 | 51 | if __name__ == '__main__': 52 | main() 53 | -------------------------------------------------------------------------------- /Medium-Questions/79-safe-locker/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | شرکت آنلیم به تازگی یک گاوصندوق جدید خریده است که برای باز کردن آن باید رمز عبور را به درستی وارد کنید. رمز عبور از چند کلمه تشکیل شده است و برای باز کردن قفل، باید یکی از حروف هر کلمه را به صورت عمودی تراز کنید. برای تراز کردن کلمه ها از * در پشت هر کلمه استفاده میکنیم. این گاو صندوق هوشمند است و هر بار کلمه ها و حرف را به برنامه شما میدهد و برنامه شما باید آنها را تراز کند. 5 | 6 | برای مثال فرض کنید که به ترتیب 5 کلمه apple و orange و pear و pineapple و durian را داریم و میخواهیم آنها را با حرف a به صورت عمودی تراز کنیم. خروجی برنامه باید مانند عکس زیر باشد. 7 | 8 | 9 | نکات چالش 10 | اگر حرف مورد نظر در یک کلمه وجود ندارد برنامه باید آن کلمه را نادیده بگیرد و چاپ نکند. 11 | اگر حرف مورد نظر چند بار در یک کلمه تکرار شده بود برنامه باید حرف اول را تراز کند. 12 | استفاده از * باید کمینه باشد. 13 | 14 | 15 | ورودی 16 | در خط اول ورودی یک حرف آمده است که بر اساس آن حرف باید کلمه ها را با هم تراز کنیم. 17 | 18 | در خط دوم ورودی عدد n آمده است که نشانگر تعداد کلمات است. 19 | 20 | در n خط بعدی در هر خط یک کلمه آمده است که باید آنها را تراز کنیم. 21 | 22 | 1 ≤ n ≤ 100 23 | 24 | خروجی 25 | در خروجی باید رمز عبور تراز شده با همان ترتیبی که از ورودی دریافت شده است چاپ شود. 26 | 27 | ورودی نمونه 1 28 | a 29 | 5 30 | apple 31 | orange 32 | pear 33 | pineapple 34 | durian 35 | خروجی نمونه 1 36 | ****apple 37 | **orange 38 | **pear 39 | pineapple 40 | durian 41 | در خط اول حرف a آمده است که رمز باید بر اساس آن به صورت عمودی تراز شود. در خط دوم n آمده و در n خط بعدی کلمات آمده است. در نهایت رمز عبور بر اساس حرف a تراز شده و چاپ شده است. 42 | 43 | ورودی نمونه 2 44 | e 45 | 5 46 | apple 47 | orange 48 | pear 49 | pineapple 50 | durian 51 | خروجی نمونه 2 52 | *apple 53 | orange 54 | ****pear 55 | **pineapple 56 | 57 | https://unlim.ir/contest/26 -------------------------------------------------------------------------------- /Medium-Questions/80-valid-parentheses/Python/app.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def isValid(self, s): 3 | """ 4 | :type s: str 5 | :rtype: bool 6 | """ 7 | open_mapper = { 8 | "}": "{", 9 | "]": "[", 10 | ")": "(" 11 | } 12 | stack = set() 13 | for char in s: 14 | if char in "{[(": 15 | stack.add(char) 16 | elif open_mapper[char] == stack.pop(): 17 | continue 18 | else: 19 | return False 20 | 21 | return True 22 | 23 | 24 | 25 | 26 | if __name__ == '__main__': 27 | s = "([])" 28 | print(Solution().isValid(s)) -------------------------------------------------------------------------------- /Medium-Questions/80-valid-parentheses/README.md: -------------------------------------------------------------------------------- 1 | 20. Valid Parentheses 2 | 3 | Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. 4 | 5 | An input string is valid if: 6 | 7 | Open brackets must be closed by the same type of brackets. 8 | Open brackets must be closed in the correct order. 9 | Every close bracket has a corresponding open bracket of the same type. 10 | 11 | 12 | Example 1: 13 | 14 | Input: s = "()" 15 | 16 | Output: true 17 | 18 | Example 2: 19 | 20 | Input: s = "()[]{}" 21 | 22 | Output: true 23 | 24 | Example 3: 25 | 26 | Input: s = "(]" 27 | 28 | Output: false 29 | 30 | Example 4: 31 | 32 | Input: s = "([])" 33 | 34 | Output: true 35 | 36 | 37 | 38 | Constraints: 39 | 40 | 1 <= s.length <= 104 41 | s consists of parentheses only '()[]{}'. -------------------------------------------------------------------------------- /Medium-Questions/81-RGB-supplement/Python/app.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | def main(): 4 | x = int(input()) 5 | colors = [input().split("#")[-1] for i in range(x)] 6 | for color in colors: 7 | r, g, b = int(color[:2], base=16), int(color[2:4], base=16), int(color[4:6], base=16) 8 | c = f"#{str(hex(255-r)).replace('0x', '').zfill(2)}{str(hex(255-g)).replace('0x', '').zfill(2)}{str(hex(255-b)).replace('0x', '').zfill(2)}" 9 | print(c.upper()) 10 | 11 | 12 | if __name__ == '__main__': 13 | main() -------------------------------------------------------------------------------- /Medium-Questions/81-RGB-supplement/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | https://quera.org/problemset/244098 -------------------------------------------------------------------------------- /Medium-Questions/81-RGB-supplement/doc/quiz.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alisharify7/Programming-Questions/ead450f085e188ad1cc563be6ba2712b5d48f20f/Medium-Questions/81-RGB-supplement/doc/quiz.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | GitHub repo size 3 | GitHub contributors 4 |

5 | 6 | Donate/Support [Optional] 7 | 8 | see also ALgorithms Repo 9 | 10 | (en English) 11 | 12 | ## Solve Some Programming Questions Together In Here - That Available On The Internet 13 | ### question + code (answer) 14 | 15 | - In Medium-Questions are Some Basic and Useful questions for Beginners to practice programming and Help you to Understand Problem-Solving :) 16 | 17 | + How to clone : 18 | 19 | git clone https://github.com/alisharify7/Programming-Questions.git 20 | git pull https://github.com/alisharify7/Programming-Questions.git 21 | 22 | see other git commands at: https://github.com/joshnh/Git-Commands 23 | 24 | ___ 25 | 26 | (Fa Persian) 27 | 28 | ## حل بعضی از سوالات برنامه نویسی که در سطح اینترنت هست به همراه جواب 29 | 30 | ### هدف کلی من از این ریپازیتوری درست کردن یه منبع کامل از سوالات به همراه جواب هست برای تقویت -حل مسئله- تا افراد با حل کردن روزانه از این سوالات خودشون رو عادت به حل -مسائل- جدید و روش های جدید کنند 31 | 32 | ### سوالات بر اساس شماره بندی هستن و از سطح آسون به سخت پیش میرند 33 | 34 |
35 | 36 | - در Medium-Questions مجموعه سوالاتی هست برای افراد مبتدی تا سطح متوسط وجود داره که هر سوال با توجه به هدفی که داره مطالب جدد به برنامه نویس یاد میده از اپراتور های جدید تا شاید کتابخونه های داخلی اون زبان 37 | 38 | 39 | ___ 40 | - اگر سوالی دارید که فکر می کنید به درد این ریپازیتوری میخوره طبق قواعد زیر ارسال کنید 41 | + برای contribute کردن اگر سوالی دارید تو قالب زیر ارسال کنید : 42 | + یه پوشه به اسم سوال درست کنید داخل پوشه حتما یه فایل Readme بزارید با شرح سوال 43 | + و بعد یه پوشه به اسم زبانی که حلش کردید بسازید که داخلش خود فایل اصلی کدتون باشه 44 | 45 | مثال: نام مسئله=> Missing Number 46 | 47 | زبانی که سوال رو حل کردید پایتون 48 | 49 | یه فولدر ابتدا به اسم Missing Number بسازید 50 | 51 | داخل همین فولدر یه فایل readme با شرح سوال بزارید 52 | 53 | داخل همین فولدر, فولدر ای به اسم Python (زبانی که سوال رو حل کردید) بسازید 54 | 55 | داخلش فایل اصلی کدتون رو قرار بدید و تمام ! :) 56 | 57 | --------------------------------------------------------------------------------