Mini-Tutorial Python

#defines a function that calculates the factorial

def factorial(n):
    if n <= 1:
        return 1
    return n*factorial(n-1)

print "2! = ",factorial(2)
print "3! = ",factorial(3)
print "4! = ",factorial(4)
print "5! = ",factorial(5)
      
2! =  2
3! =  6
4! =  24
5! =  120
      
which_one = input("What month (1-12)? ")
months = ['January', 'Feburary', 'March',\
          'April', 'May', 'June', 'July',\
          'August', 'September', 'October',\
          'November', 'December']
if 1 <= which_one <= 12:
        print "The month is",months[which_one - 1]
      
What month (1-12)? 3
The month is March
      
#Write a file
out_file = open("test.txt","w")
out_file.write(\
  "This Text is going to out file\nLook at it and see\n")
out_file.close()

#Read a file
in_file = open("test.txt","r")
text = in_file.read()
in_file.close()

print text, 
This Text is going to out file
Look at it and see
      
AnteriorInicioSiguiente