 dketov
12/11/2011 - 7:11 PM

## Целое число

Целое число

``````# -*- encoding: utf-8 -*-
"""
Ввод из консоли
"""
number = input('Enter a number between 1 and 10: ')
if number <= 10:
if number >= 1:
print 'Great!'
else:
print 'Wrong!'
else:
print 'Wrong!'
``````
``````# -*- encoding: utf-8 -*-
"""
Сравнение
"""

# read string and convert to integer
number1 = raw_input( "Please enter first integer: " )
number1 = int( number1 )

number2 = raw_input( "Please enter second integer: " )
number2 = int( number2 )

if number1 == number2:
print "%d is equal to %d" % ( number1, number2 )

if number1 != number2:
print "%d is not equal to %d" % ( number1, number2 )

if number1 < number2:
print "%d is less than %d" % ( number1, number2 )

if number1 > number2:
print "%d is greater than %d" % ( number1, number2 )

if number1 <= number2:
print "%d is less than or equal to %d" % ( number1, number2 )

if number1 >= number2:
print "%d is greater than or equal to %d" % ( number1, number2 )
``````
``````# -*- encoding: utf-8 -*-
"""
Получение из строки
"""

car = "123"
car = int(car)

rent = int("12")

total = car + rent

print "\nGrand Total: ", total
``````
``````# -*- encoding: utf-8 -*-
"""
Преобразование
"""

print int('0100'), int('0100', 8), int('0x40', 16)
``````
``````# -*- encoding: utf-8 -*-
"""
Остаток и возведение в степень
"""

a = 3                     # name created
b = 4

print a % 2, b ** 2       # modulus (remainder), power``````
``````# -*- encoding: utf-8 -*-
"""
Определение и использование
"""

a = 3                     # name created
b = 4

print b * 3, b / 2        # multiplication (4*3), division (4/2)``````