[Tutor] Truckers Log....Me Again

glidedon glidedon <glidedon@c-zone.net>
Sun, 20 Jan 2002 21:46:53 +0000


>
>It sounds like you want to do something like the following pseudocode
>
>##
>while 1:
>    read the input x
>    if x == yes:
>        do this
>    elif x == no:
>        do the other thing
>    else:
>        print some warning
>###
>
>
>This is often called a "read-eval-print" loop:
>
>    1.  We read some input from the user.
>    2.  We evaluate or interpret that response.
>    3.  We print out some output.
>    4.  Repeat!
>
>and is often used with interactive programs that need to read input from a
>user.
>
>
>Hope this helps!

I must be thick headed! When I substitue elif for if, in the code below I get 
this error:

SyntaxError: invalid syntax
/boot/home/py>LogRecapv1.3.py
  File "./LogRecapv1.3.py", line 47
    elif : add_days  in ( 'n', 'N', 'no', 'NO' ):
       ^               
The program works as is below but it exits after the last line. You can see 
what I was trying before your sugestion in the lines I commented out at the 
bottom.

Thanks Danny !
 
# Logbook 8 day recap

# this program will calculate hours on duty last 7 days,
# hours avalible tomorrow(70 hours minus total last 7 days on duty) ,hours on 
duty last 8 days
# for a truck drivers log book


#create list for storing hours on duty record

history_list = [ ]

last_7_days = 0
print ' \n '  *2 , ' Welcome to Don\'s Recap Calculator ! ', ' \n ' 
print ' I hope this makes recaping your log easier. ' , ' \n '

# populate history_list with first 8 days of recap and convert to float

for i in range( 8 ):
    querry_string = " Enter total hours on duty on day%d   "  % ( i +1 )
    input = raw_input(querry_string)
    history_list.append( float( input ) )
    
# ask for additional days input

add_days = raw_input( 'Do you want to add more days to recap ?  y/n   : ' )

# create loop to check if the answer is y or n, or some variation of
# assign value of the last  7 entries in history_list to the variable 
last_7days
# output current recap status
# continue loop for more input

while  add_days in ( 'y','Y', 'yes','YES', 'ok', 'OK', 'yeah', 'YEAH' ) : 
    next_day =raw_input( ' Enter hours on duty next day : ')
    history_list.append( float (next_day ) )
    print  ' \n', '='*20,'RECAP', '=' *33,' \n', '=' * 60 
    import operator
    last_7_days = reduce( operator.add,history_list[ -7: ] )
    print ' Total hours on duty last 7 days    : ',  last_7_days
    print ' Total hours available tomorrow     : ' , 70 - last_7_days
    print ' Total hours on duty last 8 days    : ' , last_7_days + 
history_list [ -8 ]
    print ' You have entered ' , len(history_list), ' Days ', ' \n' 
    print '  ' ,history_list, '\n' , '=' * 60, '\n'
    add_days = raw_input( 'Do you want to add more days to recap ?  y/n   : ' 
)

if add_days  in ( 'n', 'N', 'no', 'NO' ):
           print  ' \n', '='*20,'RECAP', '=' *33,' \n', '=' * 60 , ' \n '
           import operator
           last_7_days = reduce( operator.add,history_list[ -7: ] )
           print ' Total hours on duty last 7 days    : ',  last_7_days
           print ' Total hours available tomorrow     : ' , 70 - last_7_days
           print ' Total hours on duty last 8 days    : ' , last_7_days + 
history_list [ -8 ]
           print ' You have entered ' , len(history_list), ' Days ', ' \n' 
           print '  ' ,history_list
           print  ' \n', '='*20,'EXIT', '=' *34,' \n', '=' * 60 
           print ' \n ' *2, 'Thanks for using Don\'s Recap calculator ! ', ' 
\n '*2, 'Have a safe trip :-) ',' \n' *3

 #elif add_days != ( 'y','Y', 'yes','YES', 'ok', 'OK', 'yeah', 'YEAH' ) or( 
'n', 'N', 'no', 'NO' ):
           #print ' Nice try good buddy, enter a y/n , ten-four ? '
           
else: 
      print ' Nice try good buddy, enter a y/n , ten-four ? '
  
        
   

-- 
BeTween the BeS is the BeAutiful
BeCalm

AbitBE6, PIII 500, 192ram, AIW 128 Pro AGP,IBM udma66 9g,      WD UDMA33 9g, 
HP 8200i CDRW, Pioneer 106s DVD

 Running BeOS 5.03 THE best OS on the Planet!