Free Essay

Acc Python Lab 9

In:

Submitted By nikolai0505
Words 1265
Pages 6
Algorithm
High Card prompt for the name of player 1 and player 2 initialize two card objects and call the .deal() method print to the players to show what card by calling .get_face_value() on the card objects display the result (if card 1 > card 2 display player1 won else if card 2 > card1 display player 2 won, else display tie)
Face_value
if card is 1 display ace if card is 2 display two if card is 3 display three if card is 4 display four if card is 5 display five if card is 6 display six if card is 7 display seven if card is 8 display eight if card is 9 display nine if card is 10 display ten if card is 11 display jack if card is 12 display queen if card is 13 display king make change prompts user for the cost of the item prompts user for the amount tendered determines how much change if any is returned to the customer by subtracting amount tendered by the cost of the item prints 'customer still owes money' if the amount tendered is not greater than or equal to the amount owed prints the change in the amount of dollar bills, quarters, dimes, nickels and pennies owed back to the customer deal hand creates 5 card objects and gives them values with the .deal() method puts the 5 Card objects in a list calls the method display_hand() to display the face value of each card in the list calls the method hand_stats() to give the stats of the hand such as: the highest/lowest card and the total/average value of the cards menu prints the menu and prompts the user to select an option checks to make sure that the user inputted a correct value, if not displays error using that selection it determines which function the user wants the program to execute (if option 1 call make_change, if option 2 call high_card, if option 3 call deal_hand, if option 4 save dream hand, option 5 display dream hand, option 6 word guess, option 7 quit )

save dream hand try clause create list with 5 elements assign the value 0 to number (index for while loop) assign the value 0 to value loop while number is less than 5 read in from the keyboard the numeric value for the user’s dream hand and assign this to value (don’t forget to change it to a int) then use an if statement to validate that the user can read and inputted a value between 1 and 13 if the user didn’t mess up create a Card object and using the set_value method set the value of the card to the value the user inputted assign the Card to the index of [number] in the list increment number by 1 so there isn’t an endless loop if the user inputs the wrong character print a statement saying that this program only wants a number between 1 and 13(end loop) asks for a file name to save it under and save that into a variable called file_name then create a variable named outfile and open the file using file_name and specify that you are writing a file with ‘w’ then create a for loop that loops through each Card in the list, calls get_value and writes the value to the file change it to a string then close the file outside of the for loop finally write your exception in this case ValueError in case they input non numeric characters display dream hand try clause asks the user for the file name in which he saved his dream hand to and save it in the file_name variable create a variable called infile that specified that it is opening the file that the user specified in variable fine_name create a list with 5 elements create a variable that will be a count for the upcoming while loop create a loop while the variable acting as a count is less than 5 in the loop read in each line from the file to a variable of your choosing in the loop, use the rstrip method to remove the new line characters from the end of the variable you just read a line into in the loop, create a Card object and set_value the value read in from the file also call set_face_value using the value read in increment the count (end of loop code) display the dream hand using the display_hand method (reference display_hand for details) close the file so that it isn’t accidentally referenced or read from later word_guess read in a word from the keyboard into variable ‘word’ print 100 new lines make the word lower case for case uniformity create a string variable to keep track of the letters guessed (I named mine guessed) find the length of word and assign it into an appropriately named variable (length) now create a variable to monitor the progress of the player (progress) and assign it ‘*’ for each letter in word (don’t hardcode it there is a reason we found the length of word) create a boolean variable (condition) and assign it the value False create a loop that will loop while condition is False in the loop, ask the user to a guess a letter and save into a variable (letter) write an if statement to check and see if the user already guessed that letter by seeing if that letter is already present in the variable guessed if so tell them if not add the letter to guessed write an if statement to check if that letter can be found in word if not tell them to try again if so create a count variable then write a loop that will continue while the count variable is less than the length of word in the loop have an if statement that checks if letter is equal to the letter in word at the count variables index if so replace ‘*’ with letter at its appropriate index increment index by 1 check if (progress) equals (word) if true, change (condition) to True and print a statement informing them of their success if not, print (guessed) and (progress)

main variable (option) to store the return value received after calling menu() loop while (option) isn’t 7 if 1 call make_change() if 2 call high_card() if 3 call deal_hand() if 4 call save_dream_hand() if 5 call display_dream_hand() if 6 call word_guess() call the menu and store the returned value in variable (option) display_hand parameter is a list of Card objects loops for each item in that list calls .get_face_value for each item to return the face value to be printed hand_stats parameter is a list of Card objects create another list to hold the values of the 5 Cards loop through the list of Cards and use the get_value() method to return a value for the list of card values print the highest value card use the max method on the list of card values and save into a variable (number) call face_value on number print the lowest value card use the min method on the list of card values and save into a variable (number call face_value on number for loop goes through each card value in the list of card values and adds them up into a variable( total) prints the total value of the hand divides total by 5 and saves into a variable (average) (hard coded only because the total number of cards in a hand is 5) prints the average value of the hand

Similar Documents

Premium Essay

B2B Advantages and Disadvantages

...This page intentionally left blank Te n t h E d i t i o n MODERN DATABASE MANAGEMENT Editorial Director: Sally Yagan Editor in Chief: Eric Svendsen Executive Editor: Bob Horan Editorial Project Manager: Kelly Loftus Editorial Assistant: Jason Calcano Director of Marketing: Patrice Lumumba Jones Marketing Manager: Anne Fahlgren Marketing Assistant: Melinda Jensen Senior Managing Editor: Judy Leale Project Manager: Becca Richter Senior Operations Supervisor: Arnold Vila Operations Specialist: Ilene Kahn Senior Art Director: Jayne Conte Cover Designer: Suzanne Behnke Cover Art: Fotolia © vuifah Manager, Visual Research: Karen Sanatar Permissions Project Manager: Shannon Barbe Media Project Manager, Editorial: Denise Vaughn Media Project Manager, Production: Lisa Rinaldi Supplements Editor: Kelly Loftus Full-Service Project Management: PreMediaGlobal Composition: PreMediaGlobal Printer/Binder: Edwards Brothers Cover Printer: Lehigh-Phoenix Color/Hagerstown Text Font: Palatino Credits and acknowledgments borrowed from other sources and reproduced, with permission, in this textbook appear on appropriate page within text. Microsoft® and Windows® are registered trademarks of the Microsoft Corporation in the U.S.A. and other countries. Screen shots and icons reprinted with permission from the Microsoft Corporation. This book is not sponsored or endorsed by or affiliated with the Microsoft Corporation. Copyright © 2011, 2009, 2007, 2005, 2002...

Words: 193467 - Pages: 774

Free Essay

The Origins and Development of the English Language (Textbook)

...THE ORIGINS AND DEVELOPMENT OF THE ENGLISH LANGUAGE This page intentionally left blank THE ORIGINS AND DEVELOPMENT OF THE ENGLISH LANGUAGE SIXTH EDITION ± ± John Algeo ± ± ± ± ± Based on the original work of ± ± ± ± ± Thomas Pyles Australia • Brazil • Japan • Korea • Mexico • Singapore • Spain • United Kingdom • United States The Origins and Development of the English Language: Sixth Edition John Algeo Publisher: Michael Rosenberg Development Editor: Joan Flaherty Assistant Editor: Megan Garvey Editorial Assistant: Rebekah Matthews Senior Media Editor: Cara Douglass-Graff Marketing Manager: Christina Shea Marketing Communications Manager: Beth Rodio Content Project Manager: Corinna Dibble Senior Art Director: Cate Rickard Barr Production Technology Analyst: Jamie MacLachlan Senior Print Buyer: Betsy Donaghey Rights Acquisitions Manager Text: Tim Sisler Production Service: Pre-Press PMG Rights Acquisitions Manager Image: Mandy Groszko Cover Designer: Susan Shapiro Cover Image: Kobal Collection Art Archive collection Dagli Orti Prayer with illuminated border, from c. 1480 Flemish manuscript Book of Hours of Philippe de Conrault, The Art Archive/ Bodleian Library Oxford © 2010, 2005 Wadsworth, Cengage Learning ALL RIGHTS RESERVED. No part of this work covered by the copyright herein may be reproduced, transmitted, stored, or used in any form or by any means graphic, electronic, or mechanical, including...

Words: 164520 - Pages: 659

Free Essay

Gd-Pi

...Hundreds(of(real(personal(accounts(of Group'Discussions'&'Personal'Interviews during(MBA(admissions(to(India’s(best(B9schools Written'by Compiled'by Loads'of'MBA'Aspirants The'PaGaLGuY'MadCapz'Group PaGaLGuY.com Antholo gy Hundreds of real personal accounts of Group Discussions and Personal Interviews during MBA admissions to India’s best business schools. In this edition: The IIMs at Ahmedabad, Bangalore, Calcutta, Lucknow, Indore & Kozhikode. Written by Loads of MBA aspirants Compiled by The PaGaLGuY MadCapz Team PaGaLGuY GD-PI Anthology Copyright © 2011, PaGaLGuY.com All text and content in this document is solely owned by PaGaLGuY.com. Reproduction without permission in any form or means is illegal. Special copy prepared exclusively for mustafa rokerya Get your own Free personalized copy (with your name on it) of this book from http://www.pagalguy.com/books/ What this book is about What is a real IIM interview like? What kind of questions do they ask and what judgments do applicants have to make while answering them? Since 2003, those with real Group Discussion and Personal Interview calls from India’s top bschools have been posting entire and detailed transcripts of their admission interviews immediately after they happen, so that others slotted for later interviews can learn what GDPI is going to be like this year. This book is a collection of dozens of handpicked GDPI experiences from the country’s top bschools during the admission...

Words: 178933 - Pages: 716