<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:arial, helvetica, sans-serif;font-size:10pt"><div>I'm stuck on two problems from the Absolute Beginners book. The first is simple. I am trying to print all the words in the list in random order without repeats, but it always shows None for some reason.</div><div><br></div><div><div><span class="Apple-style-span" style="font-size: x-small;">#Program prints list of words in random order with no repeats</span></div><div><span class="Apple-style-span" style="font-size: x-small;"><br></span></div><div><span class="Apple-style-span" style="font-size: x-small;">import random</span></div><div><span class="Apple-style-span" style="font-size: x-small;"><br></span></div><div><span class="Apple-style-span" style="font-size: x-small;">#List of words</span></div><div><span class="Apple-style-span" style="font-size: x-small;"><br></span></div><div><span
class="Apple-style-span" style="font-size: x-small;">list = ["first", "second", "third", "fourth","fifth"]</span></div><div><span class="Apple-style-span" style="font-size: x-small;"><br></span></div><div><span class="Apple-style-span" style="font-size: x-small;">#Randomize word order</span></div><div><span class="Apple-style-span" style="font-size: x-small;"><br></span></div><div><span class="Apple-style-span" style="font-size: x-small;">order = random.shuffle(list)</span></div><div><span class="Apple-style-span" style="font-size: x-small;"> </span></div><div><span class="Apple-style-span" style="font-size: x-small;">#Print words in random order</span></div><div><span class="Apple-style-span" style="font-size: x-small;">print(order)</span></div><div><span class="Apple-style-span" style="font-size: x-small;"><br></span></div><div><span class="Apple-style-span" style="font-size: x-small;">input("\n\nPress the Enter to
exit")</span></div></div><div><span class="Apple-style-span" style="font-size: x-small;"><br></span></div><div><span class="Apple-style-span" style="font-size: x-small;"><br></span></div><div><span class="Apple-style-span" style="font-size: small;">The other question is: "Improve the program by adding a choice that lets the user enter a name and get back a grandfather. You should still only use one list of son-father pairs. Make sure to include several generations in list so a match can be found." The only thing I have done is adding choice 5 with its basic elif block and adding another name in each of the three sequences </span><span class="Apple-style-span" style="font-size: small; ">in the list</span><span class="Apple-style-span" style="font-size: small; ">, but I am completely stuck otherwise.</span></div><div><span class="Apple-style-span" style="font-size: small; "><br></span></div><div><span class="Apple-style-span" style="font-size:
x-small;"><div>#User can enter name of male and name of his father will show</div><div>#Allow user to add, replace, and delete son-father pairs.</div><div>#Also have the user enter a name to get back a grandfather</div><div><br></div><div>#Setting values</div><div>sondad = {"Vincent": "Ramon": "Lolo","Jesus": "God": "Unknown", "Simba": "Mufasa": "Lion"}</div><div><br></div><div>choice = None</div><div>while choice != "0":</div><div><br></div><div> print(</div><div> """</div><div> Who's Your Daddy?!</div><div> </div><div> 0 - Quit</div><div> 1 - Look Up Pair</div><div> 2 - Add a Pair</div><div> 3 - Replace a Pair</div><div> 4 - Delete a Pair</div><div> 5 - Look up a Grandfather</div><div> </div><div> """</div><div>
)</div><div><br></div><div> choice = input("Choice: ")</div><div> print()</div><div><br></div><div> # exit</div><div> if choice == "0":</div><div> print("Good-bye.")</div><div><br></div><div> # look up pair</div><div> elif choice == "1":</div><div> choice = input("Which pair do you want to look up?: ")</div><div> if choice in sondad:</div><div> dad = sondad[choice]</div><div> print("\n", choice,"is son to:", dad)</div><div> else:</div><div> print("\nSorry, I don't know", choice)</div><div><br></div><div> # add a father</div><div> elif choice ==
"2":</div><div> choice = input("Who is the son you want to add?: ")</div><div> if choice not in sondad:</div><div> dad = input("\nWho's the father?: ")</div><div> sondad[choice] = dad</div><div> print("\n", dad, "has been added.")</div><div> else:</div><div> print("\nThat pair already exists! Try replacing them.")</div><div><br></div><div> # replace a father</div><div> elif choice == "3":</div><div> choice = input("Which son do you want to replace a father?: ")</div><div> if choice in sondad:</div><div> dad = input("Who's the
father?: ")</div><div> sondad[choice] = dad</div><div> print("\n", choice, "has been replaced.")</div><div> else:</div><div> print("\nThey don't exist! Try adding them.")</div><div> </div><div> # delete a pair</div><div> elif choice == "4":</div><div> choice = input("Which pair do you want to delete?: ")</div><div> if choice in sondad:</div><div> del sondad[choice]</div><div> print("\nOkay, I deleted", choice)</div><div> else:</div><div> print("\nI can't do that!", choice, "don't
exist.")</div><div><br></div><div> # look up grandfather:</div><div> elif choice == "5":</div><div> choice = input("Who's grandfather are you looking up?: ")</div><div> if choice in sondad:</div><div> dad = sondad[choice]</div><div> print("\n", choice,"is grandson to:", dad)</div><div> else:</div><div> print("\nSorry, I don't know", choice)</div><div> </div><div> # some unknown choice</div><div> else:</div><div> print("\nSorry, but", choice, "isn't a valid choice.")</div><div> </div><div>input("\n\nPress the enter key to
exit.")</div><div> </div><div><br></div></span></div><div></div><div><br></div><div style="position:fixed"></div>
<!-- cg2.c902.mail.ac4.yahoo.com compressed/chunked Fri Jun 10 01:22:23 UTC 2011 -->
<div id="myEventWatcherDiv" style="display:none;"></div></div></body></html>