Menu

[Solved]-Python Done Simplest Form Without Importing Anything Besides Random Multiple Variables Nee Q37256285

This is for Python and should be done in the simplest form,without importing anything besides random. Multiple variables needto be converted to a list. Here are the instructions in detail:

You will modify your program to work with the hand of cards as alist of 5 integers rather than 5 separate variables.

You will modify the Deal Handfunction:

  1. Generate the 5 cards and store them in a list
  2. Pass the entire 5-card list to a new function “display_hand”that will take the list as input and go through the list one at atime and call your display_face_value function
  3. Pass the entire 5-card list to a different function“hand_stats” that will take the list as input and display the totalvalue of the cards added together and the average value of thecards in the hand. Be sure to label the output.
  4. You will modify the Save Dream Handfunction:

  5. Read the cards from the user and save in a list, not individualvariables
  6. After all 5 card values have been read andstored in a list, save the list of cards to the file  asnumbers, one per line.
  7. You will modify the Display Dream Handfunction:

  8. Read the cards from the file and save in a list, not individualvariables
  9. Pass this list to your new “display_hand” function (the one youwrote for the Deal Hand function to use) in order to display the5-card hand

Current code:

import random

def deal_hand():
#Program will use five variables for five
#random cards and display it’s face value
card_1= random.randint (1,13)
card_2= random.randint (1,13)
card_3= random.randint (1,13)
card_4= random.randint (1,13)
card_5= random.randint (1,13)
print (“nDeal Hand”)
print (“———“)
print (“nHere’s your hand: “)
print (“”)
#Display face value of each card
display_face_value (card_1)
display_face_value (card_2)
display_face_value (card_3)
display_face_value (card_4)
display_face_value (card_5)

def save_dream_hand ():
print(“nSave Dream Hand”)
#Prompt the user to enter a new file name
file_name = input(“Enter a file name: “)
#Prompt user to enter five numbers between 1-13
try:
savecard_1 = int(input(“Enter a number from 1-13: “))
savecard_2 = int(input(“Enter a number from 1-13: “))
savecard_3 = int(input(“Enter a number from 1-13: “))
savecard_4 = int(input(“Enter a number from 1-13: “))
savecard_5 = int(input(“Enter a number from 1-13: “))
savecard_file= open(file_name, “w”)
savecard_file.write(str(savecard_1) + “n”)
savecard_file.write(str(savecard_2) + “n”)
savecard_file.write(str(savecard_3) + “n”)
savecard_file.write(str(savecard_4) + “n”)
savecard_file.write(str(savecard_5) + “n”)
savecard_file.close ()
print (“nYour dream cards have been saved.”)
#Display error messages for exceptions
except ValueError:
print(“ERROR: you must enter a number”)
except:
#Prompt user to enter an existing file name and display
#contents of file
try:
file_name= input(“Enter existing file name: “)
open_file= open(file_name, “r”)
line1 = int(open_file.readline ())
line2 = int(open_file.readline ())
line3 = int(open_file.readline ())
line4 = int(open_file.readline ())
line5 = int(open_file.readline ())
open_file.close()
#display the face value of the integers in the file
display_face_value (line1)
display_face_value (line2)
display_face_value (line3)
display_face_value (line4)
display_face_value (line5)
#Display error message for files that do not exist
except FileNotFoundError:
print(“ERROR: File Not Found”)

def display_face_value (deal_card):
#Display the face value for each card
if deal_card == 1:
print (“Ace”)
elif deal_card == 2:
print (“Two”)
elif deal_card == 3:
print (“Three”)
elif deal_card == 4:
print (“Four”)
elif deal_card == 5:
print (“Five”)
elif deal_card == 6:
print (“Six”)
elif deal_card == 7:
print (“Seven”)
elif deal_card == 8:
print (“Eight”)
elif deal_card == 9:
print (“Nine”)
elif deal_card == 10:
print (“Jack”)
elif deal_card == 11:
print (“Queen”)
elif deal_card == 12:
print (“King”)
  

Expert Answer


Answer to This is for Python and should be done in the simplest form, without importing anything besides random. Multiple variable… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *