Saturday, 18 October 2014

Dictionary


Dictionary:

an_example_dictionary ={1:"No Way!",2:"Hatchee How",3:"wambambam",4:"Pow!"}
print(an_example_dictionary)
print(an_example_dictionary[3])



an_example_dictionary2 ={"1":"No Way!","2":"Hatchee How","3":"wambambam","4":"Pow!"}
print(an_example_dictionary2)
print(an_example_dictionary2["3"])






2nd way:

dictionary={}
dictionary['1']=['a','b','c']
print(dictionary)
dictionary['2']=['d','e','f']
print(dictionary)








3rd way:
dictionary_non_literal={}
dictionary_non_literal[1]=['a','b','c']
dictionary_non_literal[2]=['a1','b1','c1']
print(dictionary_non_literal)

Wednesday, 1 October 2014

Siri with a Tuple

I changed my siri to use a tuple:


 #Siri!!
restart = 'y'
while restart=='y':

 import random

 user_name = input("What is yor name?\n")

                                                                          #Write answers in a tuple.
 answer=(
 "Sure Thing",
 "Why not",
 "Siri Aproves",
 "HaHa Nice!",
 "Go for it",
 "So Cool!",
 "I'm Siri",
 "Cool Story",
 )



 print ("Hi",user_name)
 print ("Meet Siri.")

                                                                          #get the users questions.

 question= input ("Ask me for advice then press ENTER to shake me?\n")
 print ("Shaking...\n"*4)

                                                                          #Create a dice.
 choice=random.randint(0,7)

                                                                          #Print answer to the screen then restart
 print (user_name,"You asked -",question)
 print("Siri says:\n",answer[choice])
 restart= input("\n\n Press y key to to play again\n")