val = 10
print "%d" %val
i_var = 10
f_var = 100.3125
print "i_var is %d and f_var is %f" %(i_var, f_var)
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
years = float(raw_input("Input your age in years: "))
secs = years*365*24*60*60
print "You have lived for %0.1f seconds" %secs
c = '#'
print "This is the hash symbol: %s" %c
code = int(raw_input("Input an ASCII code (0 to 127):" ))
symbol = chr(code)
print "The symbol corresponding to %d is %s" %(code,symbol)
my_string = "13 is unlucky."
print "my_string: %s" %my_string
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
shorti = int(raw_input("Input short int: "))
longi = int(raw_input("Input long int: "))
print "shorti = %d and longi = %d" %(shorti, longi)
print "%c" %('\x07')
#note: there won't be any beep in Python
sal = float(raw_input("Salary: "))
tax = sal * 0.3
print "tax = %.1f" %tax
tax_rate = 0.3
sal = float(raw_input("Salary: "))
tax = sal * tax_rate
print "tax = %.1f" %tax
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
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
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?"
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
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
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
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
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
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
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
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