|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
||||
|
||||
|
Is their a way to check, for example, in the last 2 digits in a number are 3. If so, how?
Thanks.
__________________
Before you criticize someone, walk a mile in their shoes, that way when you do criticize them, you're a mile away and you have their shoes! |
|
#2
|
||||
|
||||
|
Well I can't think of a way to check that for ints. However, that'd be easy with strings.
Say you have received an int called someint. Code:
somestr = str(someint) if somestr[-2:] == '33': print 'Yay!' else: print 'Nay.' Hope this answered your question. There's a mathematical way to do it, but I'm not too sure about the efficiency of my method, so I'll stick to that string method. |
|
#3
|
||||
|
||||
|
OK, I'll try that.
Thanks. |
|
#4
|
|||
|
|||
|
The simplest way to check an integer is to use the modulus operator (%).
eg. Code:
x = 45233 if x % 100 == 33: print 'yep' |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Math/Number Theory? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|