(Very Newbie) Problems defining a variable

Bruno Desthuilliers bruno.42.desthuilliers at websiteburo.invalid
Fri Dec 12 13:56:22 CET 2008


feba a écrit :
> On Dec 12, 5:56 am, Bruno Desthuilliers <bruno.
> 42.desthuilli... at websiteburo.invalid> wrote:
(snip)
>> I guess you wanted your first test to be:
>>
>>     if bank <= 9999:
>>        ...
(snip)
> that's it, thanks! was confused with it being basically in a column of
> all >= *.
> 
> I replaced it with
> 
> 	if bank <= 0:
> 		print("You're in the red!")
> 		quit()
> 	elif bank >= 1 and bank <= 9999:
> 		rate = 0.0060
> 	elif bank >= 10000 and bank <= 24999:
> 		rate = 0.0085
> 	elif bank >= 25000 and bank <= 49999:
> 		rate = 0.0124
> 	elif bank >= 50000 and bank <= 99999:
> 		rate = 0.0149
> 	elif bank >= 100000:
> 		rate = 0.0173
> 	else:
> 		print("What's this doing here?")
> 
> which also changes it to keep it from going on forever if you put in a
> negative amount.

Good point.

> Out of curiosity, would you still recommend applying
> an 'else' clause in this case?

Yes, but I'd use it as a replacement for the last test:

# code here ...
  	elif bank >= 50000 and bank <= 99999:
  		rate = 0.0149
  	else:
  		rate = 0.0173


And finally, I'd simplify the whole damn thing:

  	if bank < 1:
  		print("You're in the red!")
  		quit()
  	elif bank < 10000:
  		rate = 0.0060
  	elif bank < 25000:
  		rate = 0.0085
  	elif bank < 50000:
  		rate = 0.0124
  	elif bank < 100000:
  		rate = 0.0149
  	else:
  		rate = 0.0173

> I don't see how it could ever be
> triggered, even if there's an error of some kind

It couldn't, indeed. Which FWIW is a clear indication that the previous 
test ( elif bank >= 100000:) is redundant !-)

HTH



More information about the Python-list mailing list