Written as "+ main function subroutine" code structure, but also because each of the different functions in a single package the function code, to facilitate subsequent modifications, additions and deletions
Import Math
# variable representative of key switches circulation operation program
key. 1 = # function information collection DEF MyInput ():
Choice = INPUT ( ' Please select the type of calculation: (1 hours worked, 2- calculated human) ' )
IF Choice = = ' 1 ' :
size = float (the iNPUT ( ' Please enter the size of the project: (1 represents the standard size, enter decimals) ' ))
number The = int (the iNPUT ( ' Please enter the number of human :( Please enter an integer) ' ))
Time = None
return size, Number, Time
# where the returned data is a tuple if
== Choice ' 2 ' :
size = a float (INPUT ( ' Enter item size: (1 represents the standard size, enter decimal) ' ))
Number = None
Time = a float (INPUT ( ' Enter Number Enter hours :( decimal) ' ))
return size, Number, Time
# returned here is a tuple
# complete the calculation function
DEF Estimated (my_input):
# the data tuple taken out
size = my_input [0]
Number = my_input [. 1 ]
Time = my_input [2 ]
# human calculated
if(== None Number) and (Time =! None):
Number = Math.ceil (size 80 * / Time)
Print ( ' item% .1f standard size item, if necessary created% .1f man-hours, the desired number of human:% d people ' % (size, Time, number))
# hours worked
elif (number = None)! and (Time == None):
Time = 80 size * / number
Print ( ' item size% .1f standard items,% d personal use force completed, the number of man-hours required to:.% 1f a ' % (size, number the, Time))
# asking whether to continue to function
DEF Again ():
# declare global variables key, in order to modify the variable
, Ltd. Free Join key
A = the INPUT ( ' whether to continue calculating continue Enter y, enter a different key to end the program?. ' )
IF A =! ' the y- ' :
# If you do not enter 'y', put the key assignment for the 0
key = 0
# main function
DEF main ():
Print ( ' Welcome to the workload calculation applet! ' )
the while Key == 1 :
my_input = MyInput ()
Estimated (my_input)
Again ()
Print ( ' thank you for using workload calculation applet ! ' )
main ()