# There is no proper concept of Enum(Enumaration) in python so i have implemented in this manner
def enum(*sequential, **named):
enums = dict(zip(sequential, range(len(sequential))), **named)
return type('Enum', (), enums)
language = enum(human=100,animal=50,computer=51)
days = enum('SUN','MON','TUE','WED','THU','FRI','SAT')
print "human=%d, animal=%d, computer=%d" % (language.human,language.animal,language.computer)
print "SUN: %d" % days.SUN
print "MON: %d" % days.MON
print "TUE: %d" % days.TUE
print "WED: %d" % days.WED
print "THU: %d" % days.THU
print "FRI: %d" % days.FRI
print "SAT: %d" % days.SAT
# There is no proper concept of Enum(Enumaration) in python so i have implemented in this manner
def enum(*sequential, **named):
enums = dict(zip(sequential, range(len(sequential))), **named)
return type('Enum', (), enums)
units= enum(penny=1,nickel=5,dime=10,quarter=25,dollar=100)
money_unit=[units.dollar,units.quarter,units.dime,units.nickel,units.penny]
unit_name=["dollar(s)","quarter(s)","dime(s)","nickel(s)","penny(s)"]
cent=int(raw_input("Enter a monetary value in cents:"))
print "Which is equivalent to:"
tmp=0
for i in range(5):
tmp=cent / money_unit[i]
cent = cent-(tmp*money_unit[i])
if(tmp):
print "%d %s" % (tmp,unit_name[i]),
# There is no proper concept of Enum(Enumaration) in python so i have implemented in this manner
def enum(*sequential, **named):
enums = dict(zip(sequential, range(len(sequential))), **named)
return type('Enum', (), enums)
constants=enum(ITEM_NUM=3,DELT=(ord('a')-ord('A')))
def Convert2Upper(str1,str2):
str1=list(str1)
str2=list(i for i in range(len(str1)+1))
for i in range(len(str1)):
if ((ord(str1[i])>=97) and (ord(str1[i])<=122)):
str2[i]=chr(ord(str1[i])-constants.DELT)
else:
str2[i]=str1[i]
str2[i+1]='\0'
return str2
moon=["Whatever we wear","we become beautiful","moon viewing!"]
str1=""
term=0
str3=["","",""]
for i in range(constants.ITEM_NUM):
if(str1==None):
print "malloc() failed."
term=1
i=constants.ITEM_NUM
str1=Convert2Upper(moon[i],str1)
print moon[i]
str3[i]=str1
print ""
for i in range(len(str3)):
print "".join(str3[i])
# There is no proper concept of Enum(Enumaration) in python so i have implemented in this manner
def enum(*sequential, **named):
enums = dict(zip(sequential, range(len(sequential))), **named)
return type('Enum', (), enums)
con=enum(MIN_NUM=0,MAX_NUM=100)
def fRecur(n):
if(n==con.MIN_NUM):
return 0
return (fRecur(n-1)+n)
sum1=sum2=0
for i in range(1,(con.MAX_NUM)+1):
sum1+=i
sum2=fRecur(con.MAX_NUM)
print "The value of sum1 is %d." % sum1
print "The value returned by fRecur() is %d." % sum2
#The output is correct as it takes the CMD LINES from respective terminal.
import sys
print "The value received by argc is " ,len(sys.argv),".\n"
print "There are ",len(sys.argv), "command-line arguments passed to main().\n"
print "The first command-line argument is: ",sys.argv[0],"\n"
print "The rest of the command-line arguments are:\n"
for i in range(1,len(sys.argv)):
print sys.argv[i]