Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python, Kathryn Rehfield Lab 4: Repetition Due: 06/27/17 Last day accepted for h

ID: 3853476 • Letter: P

Question

Python, Kathryn Rehfield Lab 4: Repetition Due: 06/27/17 Last day accepted for half credit: 06/30/17 Add to lab 3: Lame Game Computer Game Room. Be sure to update the part of your program that describes to the user what the program will do. Make any necessary updates to your make_change game. You will have a loop in your program to control displaying the menu and playing the games. Continue to re-display the menu, read a menu option and play a game until the user enters option 3 (quit). You will now implement the High Card game. You will write a code to randomly generate two playing cards using the following rules: 1 = ace 2 – 10 = number cards 11 = jack 12 = queen 13 = king Your high_card game will ask for the first name of each player to be used when displaying the results. For purposes of this game, Ace is the lowest card. This game will “deal” two cards, one to each of the two players, and display the face value of player one’s card and player two’s card. The game will then display which player got the highest card or if it is a tie. When the High Card game is played, the output should look similar to this: Enter player 1’s name: Slydelle Enter player 2’s name: Kimminy Slydelle got a Seven Kimminy got a King Kimminy is the winner You will simulate dealing a card by generating a random number between 1 and 13. To use the random number generating function “randint”, you will need to import the module containing the code for the function. Put this line at the top of your file just under your program header comment block: import random To deal a card you will use the following statement: card1 = random.randint(1, 13) card2 = random.randint(1, 13) You can read more about the function in chapter 5 on pages 197-198. Your program will display the face value of each playing card. The decision will be based on the numeric value of the card and will display the face value using the following rules: 1 – display “Ace” 2 thru 10 – display “Two”, “Three”, etc. 11 – display “Jack” 12 – display “Queen” 13 – display “King” You will now use an input validation loop to ensure the user’s choice is valid. If the user enters an invalid option, display an error message, and re-prompt for user’s choice. You will submit the following in Blackboard: Your program source code - Not a copy pasted into a word processing document named “lab4_Firstname_Lastname.py” NOTE – Violating any of the following is grounds for getting a ZERO on your lab: You will NEVER call main() more than once. You will NEVER use pass, continue, break, exit, quit, end or ANYTHING to leave a loop, function, or other construct prematurely. You will NEVER have a function call itself. You will NEVER use global variables. However, you may use global “constants” if used properly. You will have only one return statement in a function. NOTE – Once your lab grade has been posted in Blackboard, you will have access a copy of my solution attached to your grade. Lab Grade Points Algorithm – 30 points Comments – 15 points program description major algorithm steps function descriptions (starting w/ Lab 5) Followed directions – 15 points Correct output – 15 points Structured program design – 20 points Meaningful identifier names – 5 points Program descriptions should look similar to this: ################################################ # Clovis Bagwell # # Lab 1 # # This program prompts the user for a positive integer # # and displays a message whether it is prime or not. # # The program will continue to prompt for an integer # # and display a message until the user enters a sentinel # # value of 0. # ###############################################

Assignment Lab 5: Functions COSC 1336 Programming Fundamentals I Kathryn Rehfield Lab 5: Functions Due: 07/03/17 Last day accepted for half credit: 07/07/17 Add to lab 4: Lame Game Computer Game Room. You will now put your welcome message/program description for the user into a void function. Be sure to update your description to include the new features, if any. Make any necessary updates to your program after reviewing the feedback from your previous lab. You will start organizing your code into functions. You will start by moving the central part of your code into a main function, if you have not already. This function will just be a loop that executes until the user enters the option to quit. You will create a value-returning function with all the code that 1) displays the menu and 2) makes sure the user entered a valid choice. This new menu function will not take any input, but will pass back to the calling function a valid menu choice. (Remember that program input and output is not the same thing as function input and output. Function input is what is passed in on the parameter list, NOT reading data from the keyboard. Function output is anything returned to the calling function whether it is on the parameter list or in a return statement.) You will move the code to display the face value of a card into a new function called display_face_value(). This function will take as input one numeric card value. The function will then display the one word face value of the card passed in. This function will not pass back anything to the calling function. Pay attention to the words in bold and follow the directions. I have reasons for having you do this a specific way. Adding a new option to your menu (3. Deal Hand), you will now have the following options: Make Change High Card Deal Hand Quit Make Change and High Card will now be moved into their own functions. So, if the user enters option 1, your main will call make_change(). If the user enters option 2, your main will call high_card(). When chosen, option 3 will call the deal_hand function. This function will generate, or “deal” an entire 5-card hand. You will declare 5 new variables, one for each card in a 5-card hand. Once all 5 cards have been dealt, display the face value for each of the cards in the hand. You will use your new display_face_value function to do this. You will have to call it once for each card. Again, I have reasons for having you do this a specific way, so be sure you follow the directions. You will submit the following in Blackboard: A typed algorithm for your program named “lab5_algorithm_Firstname_Lastname” which will include a separate algorithm for each function: Main Menu Make Change High Card Deal Hand Display Face Value Your program source code - Not a copy pasted into a word processing document named “lab5_Firstname_Lastname.py” NOTE – Violating any of the following is grounds for getting a ZERO on your lab: You will NEVER call main() more than once. You will NEVER use pass, continue, break, exit, quit, end or ANYTHING to leave a loop, function, or other construct prematurely. You will NEVER have a function call itself. You will NEVER use global variables. However, you may use global “constants” if used properly. You will have only one return statement in a function. NOTE – Once your lab grade has been posted in Blackboard, you will have access a copy of my solution attached to your grade. Lab Grade Points Algorithm – 30 points Comments – 15 points program description major algorithm steps function descriptions Followed directions – 15 points Correct output – 15 points Structured program design – 20 points Meaningful identifier names – 5 points Program descriptions should look similar to this: ################################################# # Clovis Bagwell # # Lab 1 # # This program prompts the user for a positive integer # # and displays a message whether it is prime or not. # # The program will continue to prompt for an integer # # and display a message until the user enters a sentinel # # value of 0. # ################################################ Function descriptions for your user-defined functions should look similar to this: ############################################### # Function: primeNumber # # Inputs: integer to test # # Outputs: 1 if prime, 0 if not prime # # Purpose: This function takes one integer input # # and determines if it is prime or not. # ##############################################

Explanation / Answer

num = int(input("Enter a number to check prime or not: "))

while(num!=0):
for i in range(2,num):
if (num % i) == 0:
print("%d is not a prime number"%num)
break
else:
print("%d is a prime number"%num)
  
num = int(input("Enter a number to check prime or not: "))