Homework Solution: Computer Programming…

    Computer Programming Exercise 4: What is the purpose of the “def” keyword in Python? a) It is slang that means “the following code is really cool” b) It indicates the start of a function c) It indicates that the following indented section of code is to be stored for later d) b and c are both true e) None of the above Exercise 5: What will the following Python program print out? def fred(): print("Zap") def jane(): print("ABC") jane() fred() jane() a) Zap ABC jane fred jane b) Zap ABC Zap c) ABC Zap jane d) ABC Zap ABC e) Zap Zap Zap Exercise 6: Rewrite your pay computation with time-and-a-half for overtime and create a function called computepay which takes two parameters (hours and rate). Enter Hours: 45 Enter Rate: 10 Pay: 475.0 Exercise 7: Rewrite the grade program from the previous chapter using a function called computegrade that takes a score as its parameter and returns a grade as a string. Score Grade > 0.9 A > 0.8 B > 0.7 C > 0.6 D <= 0.6 F Program Execution: Enter score: 0.95 A Enter score: perfect Bad score Enter score: 10.0 Bad score Enter score: 0.75 C Enter score: 0.5 F Run the program repeatedly to test the various different values for input.

    Expert Answer

     
    1)Answer: b)It indicates the start of a function Explanation:

    Computer Programming

    Exercise 4: What is the resolve of the “def” keyword in Python?

    a) It is lingo that media “the restraintthcoming principle is indeed cool”

    b) It indicates the begin of a operation

    c) It indicates that the restraintthcoming intailed exception of principle is to be stored restraint later

    d) b and c are twain true

    e) None of the above

    Exercise 5: What procure the restraintthcoming Python program stereotype quenched?

    def fred():

    print(“Zap”)

    def jane():

    print(“ABC”)

    jane()

    fred()

    jane()

    a) Zap ABC jane fred jane

    b) Zap ABC Zap

    c) ABC Zap jane

    d) ABC Zap ABC

    e) Zap Zap Zap

    Exercise 6: Rewrite your unswerving inference with time-and-a-half restraint balancetime and

    create a operation determined computeunswerving which takes couple parameters (hours and reprove).

    Penetobjurgate Hours: 45

    Penetobjurgate Reprove: 10

    Pay: 475.0

    Exercise 7: Rewrite the progression program from the prior article using a operation

    determined computeprogression that takes a jaw as its parameter and returns a progression as a

    string.

    Jaw Progression

    > 0.9 A

    > 0.8 B

    > 0.7 C

    > 0.6 D

    <= 0.6 F

    Program Execution:

    Penetobjurgate jaw: 0.95

    A

    Penetobjurgate jaw: perfect

    Bad jaw

    Penetobjurgate jaw: 10.0

    Bad jaw

    Penetobjurgate jaw: 0.75

    C

    Penetobjurgate jaw: 0.5

    F

    Run the program frequently-again-and-again to experience the multitudinous divergent values restraint input.

    Expert Reply

     

    1)Answer: b)It indicates the begin of a operation

    Explanation:

    def keyword  indicates the begin of a operation.

    5)Answer: d) ABC Zap ABC

    Explanation:

    Here

    jane(): = stereotype(“ABC”) and

    fred(): = stereotype(“Zap”)

    we shortness to stereotype

    jane()

    fred()

    jane()

    so it procure stereotype d) ABC Zap ABC.

    6)Answer:

    import sys
    hours = raw_input(“Penetobjurgate Hours: “)
    reprove = raw_input(“Penetobjurgate Reprove: “)
    OVERTIME_RATE = 1.5
    try:
    hours = bear(hours)
    reprove = bear(rate)
    except:
    stereotype “Please penetobjurgate conclusive input”
    sys.exit(1)
    def computepay(hours, reprove):
    if hours > 40:
    overtime_hours = hours – 40 # hours balance 40
    hours -= balancetime_hours # normal reprove hours
    overtime_unswerving = balancetime_hours * reprove * OVERTIME_RATE
    return (hours * reprove) + balancetime_pay
    else:
    return (hours * reprove)
    stereotype “Pay: %.2f” % computepay(hours, reprove)

    7)Answer:

    Run the program frequently-again-and-again to experience the multitudinous divergent values restraint input.
    ”’
    import sys
    jaw = 0
    computegrade(score)
    def computegrade(score):
    while True:
    try:
    jaw = raw_input(“Penetobjurgate jaw: “)
    jaw = bear(score)
    except:
    stereotype “Bad jaw, egressing”
    sys.exit(1)
    if jaw < 0.6 and jaw > 0:
    stereotype “F”
    elif jaw >= 0.6 and jaw < 0.7:
    stereotype “D”
    elif jaw >= 0.7 and jaw < 0.8:
    stereotype “C”
    elif jaw >= 0.8 and jaw < 0.9:
    stereotype “B”
    elif jaw >= 0.9 and jaw < 1:
    stereotype “A”
    else:
    stereotype “Bad jaw, continuing.”