Using pything 3.5 or later. A kidnapper kidnaps Baron Barton and writes a ransom
ID: 3790806 • Letter: U
Question
Using pything 3.5 or later.
A kidnapper kidnaps Baron Barton and writes a ransom note. It is not wrriten by hand to avoid having his hand writing being recognized, so the kid napper uses a magazine to create a ransom note. We need to find out, given the ransom note string and magazine string, is it possible to given ransom note. The kidnapper can use individual characters of words.
Here is how your program should work to simulate the ransom note problem:
your program should prompt the user to enter a long string to represent the magazine article and another short string to represent the ransom note.
your program needs to check if the magazine string contains all required characters in equal or greater number present in the ransom note.
your program should print true if it is possible to create the given ransom note from the given magazine article, and print false if it does not.
Break up your code into a set of well-defined functions. Each function should include a comment block that briefly describes it, its parameters and any return values.
Example: If the magazine string is "welcome to earth, help is needed everywhere you look"
If the ransom note is "I need money" your program should print false as not all the characters in “I need money” exist in the magazine string.
If the ransom note is "real help is not here" you program should print true since all characters in "real help is not here" exists in the magazine string.
If ransom note is "help help help" program should print false, all characters are in the magazine string but not enough to make multiple words of the same word.
Explanation / Answer
An empty access is introduced on the begin, which corresponds to the cutting-edge directory.
If the environment variable PYTHONPATH exists, as defined in environment variables, its entries are introduced next. word that on windows, paths on this variable have to be separated with the aid of semicolons, to differentiate them from the colon used in pressure identifiers (C: etc.).
extra “application paths” can be delivered inside the registry as subkeys of SOFTWAREPythonPythonCoreversionPythonPath beneath both the HKEY_CURRENT_USER and HKEY_LOCAL_MACHINE hives. Subkeys that have semicolon-delimited route strings as their default value will motive each course to be brought to sys.path. (word that each one recognised installers most effective use HKLM, so HKCU is usually empty.)
If the surroundings variable PYTHONHOME is set, it's miles assumed as “Python domestic”. otherwise, the path of the primary Python executable is used to discover a “landmark document” (Libos.py) to deduce the “Python home”. If a Python domestic is observed, the relevant sub-directories brought to sys.direction (Lib, plat-win, and so on) are based on that folder. in any other case, the center Python course is made out of the PythonPath saved in the registry.
If the Python domestic can't be placed, no PYTHONPATH is special within the environment, and no registry entries may be determined, a default direction with relative entries is used (e.g. .Lib;.plat-win, and so forth).
If a pyvenv.cfg document is observed along the main executable or inside the directory one degree above the executable, the subsequent versions observe:
If home is an absolute direction and PYTHONHOME isn't set, this course is used rather than the course to the principle executable while deducing the house area.
If applocal is ready to proper, the home belongings or the main executable is continually used as the house path, and all environment variables or registry values affecting the route are disregarded. The landmark record isn't checked.
The give up result of all this is:
when walking python.exe, or any other .exe within the fundamental Python listing (both an established version, or without delay from the PCbuild directory), the center route is deduced, and the center paths in the registry are ignored. different “application paths” inside the registry are constantly study.
while Python is hosted in every other .exe (one-of-a-kind directory, embedded thru COM, and so on), the “Python domestic” will now not be deduced, so the center course from the registry is used. other “utility paths” inside the registry are continually study.
If Python can’t locate its home and there are no registry price (frozen .exe, a few very peculiar installation setup) you get a route with a few default, but relative, paths.
For individuals who want to bundle Python into their utility or distribution, the following recommendation will save you conflicts with different installations:
include a pyvenv.cfg record alongside your executable containing applocal = true. this could make sure that your personal directory could be used to remedy paths even if you have included the usual library in a zipper record. it's going to also ignore user website online-applications and other paths indexed within the registry.
in case you are loading python3.dll or python35.dll for your personal executable, explicitly call Py_SetPath() or (at least) Py_SetProgramName() before Py_Initialize().
clear and/or overwrite PYTHONPATH and set PYTHONHOME earlier than launching python.exe from your application.
in case you cannot use the previous recommendations (for instance, you are a distribution that lets in humans to run python.exe immediately), ensure that the landmark record (Libos.py) exists for your installation directory. (observe that it's going to not be detected inside a zip file.)
these will ensure that the files in a system-huge set up will not take priority over the copy of the standard library bundled together with your software. in any other case, your customers might also experience problems the usage of your utility. be aware that the first proposal is the exceptional, as the opposite may additionally nonetheless be at risk of non-popular paths inside the registry and user website-packages.
3.6. extra modules
even though Python ambitions to be transportable among all platforms, there are functions that are particular to home windows. more than one modules, each inside the popular library and external, and snippets exist to use these features.
The windows-specific fashionable modules are documented in MS windows unique services.
three.6.1. PyWin32
The PyWin32 module by means of Mark Hammond is a group of modules for advanced home windows-precise guide. This consists of utilities for:
component item model (COM)
Win32 API calls
Registry
event log
Microsoft foundation instructions (MFC) person interfaces
PythonWin is a pattern MFC utility shipped with PyWin32. it's miles an embeddable IDE
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.