Python: 2.5.1 Painting a Wall

Python: 2.5.1 Painting a Wall

Maybe I am missing something here, but if 350 sq ft requires 1 gallon, then 250 sq ft will require 250/350 gallons. So you are being asked (I suppose) to request the area from the user and calculate the paint required for that area.

wall_area=float(input("How big is your wall in square feet? "))
gallons_paint = wall_area / 350
print(wall_area, 'square feet wall will need:')
print(gallons_paint, 'gallons of paint')

For example,

How big is your wall in square feet? 250
250.0 square feet wall will need:
0.7142857142857143 gallons of paint

Though you really ought to format the number to something sensible, as in

print(f'{gallons_paint:.2f} gallons of paint')

which will report

0.71 gallons of paint

With your other number, 576.6 square feet,

How big is your wall in square feet? 578.6
578.6 square feet wall will need:
1.65 gallons of paint

Psycopg2: to upgrade or not to upgrade

Django 2.2 supports PostgreSQL 9.4 and higher. psycopg2 2.5.4 or higher is required, though the latest release is recommended.

No, there is no need to upgrade unless specific features / bug fixes are required.

Although my personal preference is to keep up with the latest versions, especially in dev (of course, reviewing that all dependencies support it).

Yes, you will need to upgrade psycopg2 if you want to work with Postgresql 12, as support for postgresql 12 was added only since psycopg2 2.8.4.

Such core packages are well developed, maintain backwards compatibility, basic functionality barely changes.

One more note: psycopg2 was split into two packages (more separate after 2.8) - psycopg2 and psycopg2-binary. To not dig into details, this is suggested options to be set in requirements.txt (if you are using virtualenv):

  • for the start - psycopg2-binary
  • if any ssl issues, or want to build from source - then set psycopg2

Looks like you are using system-wide python packages installation, provided by os distribution repositories.

While would not suggest rushing into switching, would definitely recommend to look into using virtualenv (with helpers such as pipenv or virtualenwrapper) to have nice local python environment individually for each project with packages installed directly from pypi and not bound to os vendor.

Add method to a class which can only be accessed inside specific class

You could use refinements for this:

Due to Ruby's open classes you can redefine or add functionality to existing classes. This is called a “monkey patch”. Unfortunately the scope of such changes is global. All users of the monkey-patched class see the same changes. This can cause unintended side-effects or breakage of programs.

Refinements are designed to reduce the impact of monkey patching on other users of the monkey-patched class. Refinements provide a way to extend a class locally. Refinements can modify both classes and modules.

Something like this:

module HashPatches
refine Hash do
def new_hash_method
# ...
end
end
end

and then:

class YourClass
using HashPatches

def m
{}.new_hash_method
end
end

That would let you call YourClass.new.m (which would use new_hash_method) but it wouldn't pollute Hash globally so outside YourClass, some_hash.new_hash_method would be a NoMethodError.

Reading:

  • Official Refinements docs
  • Refinements spec

Trying to link sfml and c++ with portable vscode on windows 10

Okay, so basically I just downloaded the wrong version of SFML. I downloaded SFML Visual C++ 15 (2017) - 32-bit but the one I should have taken is SFML GCC 7.3.0 MinGW (DW2) - 32-bit. I also had to precise the name of my .exe file in tasks.json:

"-o",
"${workspaceFolder}/a.exe",


Related Topics



Leave a reply



Submit