Python Forum
What's wrong with my code?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What's wrong with my code?
#1
# 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 finished
This 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!!
Reply
#2
The problem is you pass bet_amount to playerGuessCorrect() instead of guess.
Reply
#3
(Oct-22-2021, 07:01 AM)deanhystad Wrote: The problem is you pass bet_amount to playerGuessCorrect() instead of guess.

Ohh thanks. I fixed all my code now.
Reply
#4
(Oct-22-2021, 05:30 AM)NeedHelpPython Wrote: Thanks for the help can the moderators delete this post?

That is really bad form. You posted, your solution was pointed out, and rather than leave it up so it may help someone else you edit and delete the information. We are a community here. What do you accomplish by deleting the posts?
metulburr likes this post
Reply
#5
(Oct-22-2021, 05:30 AM)NeedHelpPython Wrote: Thanks for the help can the moderators delete this post?

No, but they can revert the post, please leave the original post intact.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  im not sure what ive done wrong code doesnt run dgizzly 3 1,354 Nov-16-2022, 03:02 AM
Last Post: deanhystad
  what is wrong with my code 53535 4 1,521 Apr-07-2022, 11:37 AM
Last Post: 53535
  Help with my code due 11:59 pm, can you tell me where I went wrong and help fix it? shirleylam852 1 2,649 Dec-09-2020, 06:37 AM
Last Post: stranac
  I am getting an incorrect average, and not sure why? What's wrong with my code? shirleylam852 8 4,659 Nov-20-2020, 05:32 AM
Last Post: deanhystad
  Something is Wrong with my code susmith552 4 3,027 Nov-28-2019, 02:16 AM
Last Post: susmith552
  What is wrong with my code? Than999 1 2,371 Nov-10-2019, 08:59 PM
Last Post: ichabod801
  Wrong output on my code. JTNA 2 7,885 Apr-04-2019, 01:55 PM
Last Post: JTNA
  Why is this code wrong? Lemmy 4 5,176 Apr-05-2018, 03:46 PM
Last Post: Lemmy
  What's wrong with my code and visuals for python? beginnercoder04 2 2,797 Mar-17-2018, 01:06 AM
Last Post: beginnercoder04
  whats wrong with my code? syntax errors r6lay 5 6,466 Mar-16-2017, 04:14 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020