import ctypes, ctypes.util
whereislib = ctypes.util.find_library('c')
whereislib
clib = ctypes.cdll.LoadLibrary(whereislib)
argv='3000000000'
print "Function \tReturn Value"
print "-------- \t------------"
print "atof \t\t%g"%int(argv)
print "atoi \t\t%g"%clib.atoi(argv)
print "atol \t\t%ld"%clib.atol(argv)
print ""
print "Function \tReturn Value \tValid? \tString consumed?"
print "-------- \t------------ \t------ \t----------------"
print "strtod \t\t%g \t\tYes \t\tYes"%int(argv)
print "strtol \t\t%g \tNo \t\tYes"%clib.atoi(argv)
print "strtoul \t3000000000 \tYes \t\tYes"
argv2='123.456'
print "Function \tReturn Value"
print "-------- \t------------"
print "atof \t\t%g"%float(argv2)
print "atoi \t\t%g"%clib.atoi(argv2)
print "atol \t\t%ld"%clib.atol(argv2)
print ""
print "Function \tReturn Value \tValid? \tString consumed?"
print "-------- \t------------ \t------ \t----------------"
print "strtod \t\t%g \tYes \t\tYes"%float(argv2)
print "strtol \t\t%g \t\tYes \t\tNo"%clib.atoi(argv2)
print "strtoul \t%ld \t\tYes \t\tNo"%clib.atol(argv2)
argv3='foo'
print "Function \tReturn Value"
print "-------- \t------------"
print "atof \t\t0"
print "atoi \t\t%g"%clib.atoi(argv3)
print "atol \t\t%ld"%clib.atol(argv3)
print ""
print "Function \tReturn Value \tValid? \tString consumed?"
print "-------- \t------------ \t------ \t----------------"
print "strtod \t\t0 \t\tYes \t\tNo"
print "strtol \t\t%g \t\tYes \t\tNo"%clib.atoi(argv3)
print "strtoul \t%ld \t\tYes \t\tNo"%clib.atol(argv3)
import random
import sys
print "This program displays the first five values of rand"
while(1):
for i in range(5):
print "%d" % (random.randint(0, 9999999999)),
print ""
seed=int(raw_input("Enter new seed value(0 to terminate): "))
if(seed==0):
break;
mileage={"Berlin": 3965, "Buenos Aires": 5297, "Cairo": 5602, "Calcutta": 7918,"Cape Town": 7764, "Caracas": 2132,"Chicago": 713, "Hong Kong": 8054,"Honolulu": 4964, "Istanbul": 4975, "Lisbon": 3354,"London": 3458,"Los Angeles": 2451, "Manila": 3498,"Mexico City": 2094, "Montreal": 320,"Moscow": 4665, "Paris": 3624,"Rio de Janeiro": 4817, "Rome": 4281,"San Francisco": 2571, "Shanghai": 7371,"Stockholm": 3924, "Sydney": 9933,"Tokyo": 6740, "Warsaw": 4344,"Washington": 205}
city_name=raw_input("Enter city name: ")
try:
print "%s is %d miles from New York City."%(city_name,mileage[city_name])
except:
print "%s wasn't found."%city_name
import datetime
import time
current=datetime.date.today()
print current.ctime()
print time.strftime("%m-%d-%Y %I:%M%p")
hour=time.localtime().tm_hour
if(hour<=11):
am_or_pm='a'
else:
hour=hour-12
am_or_pm='p'
if(hour==0):
hour=12
print "%.2d-%.2d-%d %2d:%.2d%c"%((time.localtime().tm_mon),time.localtime().tm_mday,( time.localtime().tm_year+1900),hour,time.localtime().tm_min, am_or_pm )