TORONTO KIDS COMPUTER CLUB | Aurora Saturday 16:30 Python Homework 20.07.04.
17864
post-template-default,single,single-post,postid-17864,single-format-standard,ajax_fade,page_not_loaded,,qode-theme-ver-7.6.2,wpb-js-composer js-comp-ver-6.8.0,vc_responsive

Aurora Saturday 16:30 Python Homework 20.07.04.

08 Jul Aurora Saturday 16:30 Python Homework 20.07.04.

Question 1:

Create an OunceConversion object to convert any number of fluid ounces to the equivalent number of gallons, quarts, pints, and gills. (There are 128 fluid ounces in a gallon. There are 32 fluid ounces in a quart. There are 16 fluid ounces in a pint. There are 4 fluid ounces in a gill.)

  • Get the number of fluid ounces as an integer from the user; make sure to use a descriptive prompt so the user knows what to enter, e.g.:
    Sample input:

    • Please enter fluid ounces:
  • The object contains methods to calculate the total number of gallons, quarts, pints, and gills represented by the original number of fluid ounces and print it out. for example:
    • convertGallons()    – it just simply convert the ounces into gallons then print the result out, the method may have a return value
    • convertQuarts()    – it just simply convert the ounces into quarts then print the result out, the method may have a return value
    • convertPints()    – it just simply convert the ounces into pints then print the result out, the method may have a return value
    • convertGills()    – it just simply convert the ounces into gills then print the result out, the method may have a return value
  • Define __str__(self)  show calculated number of gallons, quarts, pints, gills and ounce in one line, for example:
    • “6523 fluid ounces is 50 gallon(s)+3 quart(s)+1 pint(s)+2 gill(s)+3 ounce(s)”

Question 2:
Create a PWD(Password) class it will contain the following methods:

  • __init__() – to create a password object by passing one argument into it
  • validate() – to check the validity of password input by users. it need to use the following method:
    • checkLetter: At least 1 letter between [a-z] and 1 letter between[A-Z].
    • checkNumber: At least 1 number between [0-9].
    • checkSymbol: At least 1 character from [$#@].
    • checkLength: Minimum length 6 characters. Maximum length 16 characters.

Sample program:

class PWD:
    def __init__(self, password):
        ... ...

    def validate(self):
        ... ...

    def checkLetter(self): 
        ... ...
    def checkNumber(self): 
        ... ...
    def checkSymbol(self): 
        ... ...
    def checkLength(self): 
        ... ...
myPwd = PWD(input("Please enter your password:"))
if myPwd.validate() == True:
    print("password validated!")

Sample input 1:
Please enter your password: admin123

Sample output 1:
Missing at least 1 character from [$#@]


Sample input 2:
Please enter your password: admin123$

Sample output 2:
password validated!

No Comments

Sorry, the comment form is closed at this time.