In [1]:

```
val = 10
print "%d" %val
```

In [3]:

```
i_var = 10
f_var = 100.3125
print "i_var is %d and f_var is %f" %(i_var, f_var)
```

In [1]:

```
inp_int = int(raw_input())
print "The input integer (in decimal) is %u" %inp_int
print "The input integer (in hexadecimal) is %x" %inp_int
```

In [10]:

```
years = float(raw_input("Input your age in years: "))
secs = years*365*24*60*60
print "You have lived for %0.1f seconds" %secs
```

In [12]:

```
c = '#'
print "This is the hash symbol: %s" %c
```

In [14]:

```
code = int(raw_input("Input an ASCII code (0 to 127):" ))
symbol = chr(code)
print "The symbol corresponding to %d is %s" %(code,symbol)
```

In [1]:

```
my_string = "13 is unlucky."
print "my_string: %s" %my_string
```

In [27]:

```
import sys
print "Size of a int is %d" %sys.getsizeof(int)
print "Size of a long int is %d" %sys.getsizeof(long)
#Note: there is no short interger data type in Python
#Answers will differ
```

In [3]:

```
shorti = int(raw_input("Input short int: "))
longi = int(raw_input("Input long int: "))
print "shorti = %d and longi = %d" %(shorti, longi)
```

In [4]:

```
print "%c" %('\x07')
#note: there won't be any beep in Python
```

In [7]:

```
sal = float(raw_input("Salary: "))
tax = sal * 0.3
print "tax = %.1f" %tax
```

In [8]:

```
tax_rate = 0.3
sal = float(raw_input("Salary: "))
tax = sal * tax_rate
print "tax = %.1f" %tax
```

In [9]:

```
tax_rate = 0.3
sal = float(raw_input("Salary: "))
tax = sal * tax_rate
print "tax = %.1f" %tax
#Note: there is no constant data type in Python so the program will remain same as above
```

In [10]:

```
tax_rate = 0.3
sal = float(raw_input("Salary: "))
tax = sal * tax_rate
print "tax = %.1f" %tax
#Note: there is no #define preprocessor in Python so the program will remain same as above
```

In [11]:

```
print "Input two numbers"
i = int(raw_input("num1: "))
j = int(raw_input("num2: "))
if (i == j):
print "They are equal."
print "Got the message?"
```

In [22]:

```
c = 255
d = -1
if c < 0:
print "c is less than 0"
else:
print "c is not less than 0"
if d < 0:
print "d is less than 0"
else:
print "d is not less than 0"
#the program will not have output as that given in the textbook
#because, there is no concept of char, signed or unsigned values in Python
```

In [23]:

```
c = '255'
d = '-1'
if c < 0:
print "c is less than 0"
else:
print "c is not less than 0"
if d < 0:
print "d is less than 0"
else:
print "d is not less than 0"
#the program will not have output as that given in the textbook
#because, there is no concept of char, signed or unsigned values in Python
```

In [29]:

```
i = int(raw_input("Input an integer: "))
n = int(raw_input("Bit position to extract: "))
bit = (i >> n)&1
print "The bit is: %d" %bit
```

In [33]:

```
print "Input two numbers"
i = int(raw_input("num1: "))
j = int(raw_input("num2: "))
larger = i if i > j else j
print "The larger of the two is %d" %larger
```

In [35]:

```
p = float(raw_input("Principal: "))
r = float(raw_input("Rate: "))
t = float(raw_input("Time: "))
ncmp_year = float(raw_input("Compoundings per year: "))
simple = p * r * t / 100
cmp_amount = p * pow(1 + r / (ncmp_year * 100), ncmp_year * t)
compound = cmp_amount - p
print "The simple interest is : %f" %simple
print "The compound interest is : %f" %compound
```

In [36]:

```
c = float(raw_input("Enter temperature in celsius: "))
f = 1.8 * c + 32
print "Equivalent fahrenheit = %f" %f
f = float(raw_input("Enter temperature in fahrenheit: "))
c = (f - 32) / 1.8
print "Equivalent celsius = %f" %c
```

In [39]:

```
import math
print "Enter the 3 sides: "
a = float(raw_input("side1:"))
b = float(raw_input("side2:"))
c = float(raw_input("side3:"))
peri = a + b + c
s = peri / 2
area = math.sqrt(s * (s - a) * (s - b) * (s - c))
print "Area of the triangle is %f" %area
```

In [40]:

```
b = float(raw_input("Enter the base: "))
h = float(raw_input("Enter the height: "))
area = b * h / 2
print "Area of the triangle is %f" %area
```