IDLE
.
def __init__(self, name, number):
if __name__ == '__main__': e1 = Employee("Frank", 1) print(e1.get_name(), e1.get_number()) print(e1) print() e2 = ProductionWorker('Sam', 2) print(e2.get_name(), e2.get_number(), e2.get_shift(), e2.get_rate()) e2.set_shift('one') print('shift:', e2.get_shift()) e2.set_shift(4) print('shift:', e2.get_shift()) e2.set_shift(2) print('shift:', e2.get_shift()) e2.set_rate('twenty') print('rate:', e2.get_rate()) e2.set_rate(10) print('rate:', e2.get_rate()) e2.set_rate(20) print('rate:', e2.get_rate()) print(e2)
Frank 1 Frank, 1 Sam 2 1 15.0 one cannot be converted into an integer shift: 1 shift can only be 1, 2 or 3 shift: 1 shift: 2 twenty cannot be converted into a float rate: 15.0 rate must be between 15.00 and 50.00 rate: 15.0 rate: 20.0 Sam, 2, shift: 2, rate: $20.0
pass
statement. e1 = Employee("Frank", 1)Add assignment statements for each of the attributes.
pass
statement. Employee.__init__(self, name, number)Assign shift the vale 1.
try/except
statement. try/except
statement. try
block write an assignment statement
that converts the new value into an integer. if
statement that checks whether the converted
value is in the list [1,2,3]
. else
block of the if
statement
print an error message saying the value must be ether 1, 2 or 3.except
block print an error message that the
value could not be converted into an integer. print('shift:', e2.get_shift())Run the script and fix any errors you find.
try/except
statement. try/except
statement. try
block write an assignment statement
that converts the new value into a float. if
statement that checks whether the converted
value greater than or equal to 15 and less than or equal to 50. else
block of the if
statement
print an error message saying the value must be between 15 and 50. except
block print an error message that the
value could not be converted into a float.
Uncomment the all the lines in the test code, except the last.
Run the script and fix any errors you find.
Frank 1 Frank, 1 Sam 2 1 15.0 one cannot be converted into an integer shift: 1 shift can only be 1, 2 or 3 shift: 1 shift: 2 twenty cannot be converted into a float rate: 15.0 rate must be between 15.00 and 50.00 rate: 15.0 rate: 20.0 Sam, 2, shift: 2, rate: $20.0
cd it117/hw/hw11
python3 hw11.py
Frank 1 Frank, 1 Sam 2 1 15.0 one cannot be converted into an integer shift: 1 shift can only be 1, 2 or 3 shift: 1 shift: 2 twenty cannot be converted into a float rate: 15.0 rate must be between 15.00 and 50.00 rate: 15.0 rate: 20.0 Sam, 2, shift: 2, rate: $20.0
Copyright © 2022 Glenn Hoffman. All rights reserved. May not be reproduced without permission.