Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Lesson about python Basics Copyright Usmar A. Padow (amigojapan) 2014 usmpadow@gmail.com
- #login
- #output
- print "Hello World."
- print "Enter your name"
- name=raw_input() #input
- if name=="Zack":
- print "Enter your password."
- ansyou=raw_input()
- if ansyou=="123":
- print "Welcome!"
- print "This is your palace"
- else:
- print "Get out of here!"
- quit()
- else:
- print "Hello " + name
- while True:
- print "Menu\n 1 Simple loops\n 2 Lists\n 3 Functions\n 4 Quit"
- program=raw_input()
- if program=="1":
- #1 simple loops
- #similar to repeat in scratch
- for var1 in range(5,15):
- print "var is " + str(var1)
- #In for loop, "continue" goes to the beginning and "break" goes to the end
- var2=10
- while var2>0:
- print "var 2 is " + str(var2)
- var2=var2-1
- if program=="2":
- #2 lists
- if program=="2":
- lst1=["Zack", "Usmar"]
- print "Input a name."
- name=raw_input()
- lst1.append(name)
- for element in lst1:
- print element
- str1=""
- for element in lst1:
- str1=str1+" "+element
- print str1
- #>>> str="Zack"
- #>>> str=str+" "+ "Usmar"
- #>>> print str
- #Zack Usmar
- #>>> str=str+" "+ "Yoshi"
- #>>> print str
- #Zack Usmar Yoshi
- #3 functions
- if program=="3":
- #custom functions
- #function that prints word 5 times
- def PrintFiveTimes(word):
- for counter1 in range(0,5):
- print word + str(counter1)
- #call function
- PrintFiveTimes("cafe")
- PrintFiveTimes("starbacks")
- #function that prints word X number of times
- def PrintXTimes(word,X):
- for counter1 in range(0,X):
- print word + str(counter1)
- PrintXTimes("cafe",10)
- if program=="4":
- quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement