Oct-22-2021, 05:30 AM
# you'll need the random module
from random import randint
### Write your functions below ###
def getCardValue():
result = randint(2,14)
return result
def getCardStr(cardValue):
number_string = str(cardValue)
number_string = number_string.replace("10", "K")
number_string = number_string.replace("11", "J")
number_string = number_string.replace("12", "Q")
number_string = number_string.replace("13", "K")
number_string = number_string.replace("14", "A")
return number_string
def getHLGuess():
pressenter = ""
while pressenter not in ("H","h","l","L"):
pressenter = input('High or low?(H/L): ')
if pressenter in ("L" or "l"):
return "LOW"
elif pressenter in ("H" or "h"):
return "HIGH"
def getBetAmount(maximum):
betnumber = 0
while betnumber < 1 or betnumber > maximum:
betnumber = int(input('Insert bet here :'))
return betnumber
def playerGuessCorrect(card1, card2, betType):
if betType == "HIGH" and card1 > card2:
return True
elif betType == "HIGH" and card1 < card2:
return False
elif betType == "LOW" and card1 > card2:
return True
elif betType == "LOW" and card1 < card2:
return False
elif card1 == card2 and betType == "HIGH":
return False
elif card1 == card2 and betType == "LOW":
return False
def roundtracker(points,rounds,final):
print(f"YOU MADE IT TO {points} POINTS IN {rounds} ROUNDS")
print(f"{final}")
### Write your main program below ####
msg = """--- Welcome to High-Low ---"
initalpoints = 100
current_round = 1
max_rounds = 10
current_point = initalpoints
keep_playing = True
betnumber = 0
Msg = "Start with 100 points. Each round a card will be drawn and shown.
Select whether you think the 2nd card will be Higher or Lower than the 1st card.
Then enter the amount you want to bet.
If you are right, you win the amount you bet, otherwise you lose.
Try to make it to 500 points within 10 tries."
print(msg)
def main():
global keep_playing
global current_point
keep_playing = True
print("-----------------------------------------------------------")
print(f"OVERALL POINTS: {current_point} ROUND : {current_round}/{max_rounds}")
while keep_playing:
cardvalue_1 = getCardValue()
cardvalue1 = getCardStr(cardvalue_1)
print(f"Your first card is [{cardvalue1}]!")
guess = getHLGuess()
betamount = getBetAmount(current_point)
cardvalue_2 = getCardValue()
cardvalue2 = getCardStr(cardvalue_2)
result = ""
correct = playerGuessCorrect(cardvalue_1,cardvalue_2,betamount)
result = ""
if correct == True:
current_point = current_point + betamount
result = "WIN"
else:
current_point = current_point - betamount
result = "LOSE"
print(f"Card [1] = {cardvalue1} Card [2] = {cardvalue2} You bet {guess} for {betamount} You {result}")
if current_point>=500:
roundtracker(current_point,current_round, "WIN")
keep_playing = False
elif current_point<=0 or current_round == max_rounds:
roundtracker(current_point,current_round, "LOSE")
keep_playing = False
print (f"You made it to {current_point} in {current_round}")
else:
current_round + 1
if __name__ == "__main__":
main()
input("Press enter to exit. ") # input statement to pause code when finishedThis is my code so far. I know it's not the cleanest and it maybe a bit disorganized to read. It's basically a game where it will generate you a card value and then you have to bet a certain amount of your points if the value of the card is higher or lower then the second card that is generated. You start off with 100 points and try to gamble yourself up to 500 points and then you win.The problem I'm having is that the points are not updating when the user guess them correctly or guessed them wrong into the input. Im trying to do it something like this https://ibb.co/cTMx3nR. If anyone can help me fix my code I'll be thankful!!
