Advertisement
amigojapan

Python Lesson 1

Aug 15th, 2014
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.67 KB | None | 0 0
  1. #Lesson about python Basics Copyright Usmar A. Padow (amigojapan) 2014 usmpadow@gmail.com
  2. #login
  3. #output
  4. print "Hello World."
  5. print "Enter your name"
  6. name=raw_input() #input
  7. if name=="Zack":
  8.     print "Enter your password."
  9.     ansyou=raw_input()
  10.     if ansyou=="123":
  11.         print "Welcome!"
  12.         print "This is your palace"
  13.     else:
  14.         print "Get out of here!"   
  15.         quit()
  16. else:
  17.     print "Hello " + name
  18.  
  19. while True:
  20.     print "Menu\n  1 Simple loops\n  2 Lists\n  3 Functions\n  4 Quit"
  21.     program=raw_input()
  22.     if program=="1":
  23.         #1 simple loops
  24.        
  25.         #similar to repeat in scratch
  26.             for var1 in range(5,15):
  27.                 print "var is " + str(var1)
  28.         #In for loop, "continue" goes to the beginning and "break" goes to the end
  29.        
  30.        
  31.             var2=10
  32.             while var2>0:
  33.                 print "var 2 is " + str(var2)
  34.                 var2=var2-1
  35.        
  36.     if program=="2":
  37.         #2 lists
  38.         if program=="2":
  39.             lst1=["Zack", "Usmar"]
  40.             print "Input a name."
  41.             name=raw_input()
  42.             lst1.append(name)
  43.        
  44.             for element in lst1:
  45.                 print element
  46.            
  47.             str1=""
  48.             for element in lst1:
  49.                 str1=str1+" "+element
  50.             print str1
  51.         #>>> str="Zack"
  52.         #>>> str=str+" "+ "Usmar"
  53.         #>>> print str
  54.         #Zack Usmar
  55.         #>>> str=str+" "+ "Yoshi"
  56.         #>>> print str
  57.         #Zack Usmar Yoshi
  58.    
  59.    
  60.     #3 functions
  61.     if program=="3":
  62.     #custom functions
  63.     #function that prints word 5 times
  64.         def PrintFiveTimes(word):
  65.             for counter1 in range(0,5):
  66.                 print word + str(counter1)
  67.            
  68.     #call function
  69.         PrintFiveTimes("cafe")     
  70.         PrintFiveTimes("starbacks")
  71.    
  72.     #function that prints word X number of times
  73.         def PrintXTimes(word,X):
  74.             for counter1 in range(0,X):
  75.                 print word + str(counter1)
  76.         PrintXTimes("cafe",10)     
  77.    
  78.     if program=="4":
  79.         quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement