def main():
print "This program prints a table of squares."
n=int(raw_input("Enter number of entries in table: ")) #input number of entries
i=1 #variable declaration
while(i<=n):
print "%10d%10d" % (i,i * i) #printing number and it's square
i=i+1
if __name__=='__main__':
main()
def main():
sum=0
print "This program sums a series of integers."
n=int(raw_input("Enter integers (0 to terminate): ")) #input the integers to operate on
while(n!=0):
sum=sum+n #calculating sum till 0 encountered
n=input()
print "The sum is: %d" % sum #printing sum
if __name__=='__main__':
main()
def main():
digits=0 #initialise
n=int(raw_input("Enter a nonnegative integer: ")) #input the number
n=n/10
digits=digits+1
#finding number of digits
while(n>0):
n=n/10
digits=digits+1
print "The number has %d digit(s)." % digits #printing answer
if __name__=='__main__':
main()
def main():
print "This program prints a table of squares."
n=int(raw_input("Enter number of entries in table: ")) #input number of entries
for i in range (1,(n+1)):
print "%10d%10d" % (i,i * i) #printing number and it's square
if __name__=='__main__':
main()
def main():
print "This program prints a table of squares."
n=int(raw_input("Enter number of entries in table: ")) #input number of entries
#variable declaration
i=1
odd=3
square=1
#calculation
for i in range (1,(n+1)):
print "%10d%10d" % (i,square)
square=square+odd
odd=odd+2
if __name__=='__main__':
main()
def main():
balance=0.0 #initialise
print "*** ACME checkbook-balancing program ***"
print "Commands: 0=clear, 1=credits, 2=debit, 3=balance, 4=exit"
print ""
while(1):
cmd=int(raw_input("Enter command: "))
#operate on balance according to the option selected
if cmd==0:
balance=0.0 #clear balance
elif cmd==1:
credit=float(raw_input("Enter amount of credit: "))
balance=balance+credit #credit
elif cmd==2:
debit=float(raw_input("Enter amount of debit: "))
balance=balance-debit #debit
elif cmd==3:
print "Current balance: $%0.2f" % balance #show current balance
elif cmd==4:
return 0 #exit
else:
print "Commands: 0=clear, 1=credits, 2=debit, 3=balance, 4=exit"
if __name__=='__main__':
main()