Python Forum
Beginner Higher Lower Game - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Beginner Higher Lower Game (/thread-38327.html)



Beginner Higher Lower Game - wallytan - Sep-29-2022

I am trying this beginner project of Higher Lower game. I pretty much got already 99% of the game's logic. The only thing I couldn't figure out is to keep the logo and vs stay in place while choice B keeps replacing choice A, then B picks randomly again.

Meaning:

"""LOGO""" (I want this to stay and not move/change)

Random pick here (while this would keep changing)

"""VS""" (I want this to stay and not move/change)

Random pick here (while this would keep changing)


Thanks in advanced.


def play_again():
  
  #Choice A
  a_compare = random.choice(data)
  a_followers = a_compare['follower_count']
  #########################################
  
  #Choice B
  b_compare = random.choice(data)
  b_followers = b_compare['follower_count']
  #########################################
  
  score = 0
  correct_answer = True
  # print(logo)
  # print(a_compare)
  # print(vs)
  # print(b_compare)
  while correct_answer:
    print(logo)
    print(a_compare)
    print(vs)
    print(b_compare)
    guess = input("Who has more followers. A or B: ").lower()
    if guess == 'a':
      if a_followers > b_followers:
        
        #Keep track of player's score.
        score += 1
        print(f"Correct! Your current score is {score}\n")
        #########################################
        
        #This code is for B to keep replacing A as long as guess is correct.
        a_compare = b_compare
        a_followers = b_followers
        ###################################
        
        #This code is for B to keep randomly choosing as long as guess is right.
        b_compare = random.choice(data)
        b_followers = b_compare['follower_count']
        ###################################
      else:
        correct_answer = False
        print(f"Sorry, that's wrong. Your final score is {score}")
        keep_playing()
        
    if guess == 'b':
      if b_followers > a_followers:
        
        #Keep track of player's score.
        score += 1
        print(f"Correct! Your current score is {score}\n")
        #########################################
        
        #This code is for B to keep replacing A as long as guess is correct.
        a_compare = b_compare
        a_followers = b_followers
        ###################################
        
        #This code is for B to keep randomly choosing as long as guess is right.
        b_compare = random.choice(data)
        b_followers = b_compare['follower_count']
        ###################################
      else:
        correct_answer = False
        print(f"Sorry, that's wrong. Your final score is {score}")
        keep_playing()

play_again()



RE: Beginner Higher Lower Game - menator01 - Sep-29-2022

Is this part of a bigger program?

what is a_compare['follower_count'] and b_compare['follower_count']?
where is the function keep_playing() defined?
This code will throw errors. Need more information.


RE: Beginner Higher Lower Game - deanhystad - Sep-29-2022

How much do you want the logo to stay in place? Doing that will be far more complicated than writing the game. It is possible, but will involve learning how to use a Python package designed for writing terminal user interfaces. It would be easier to write your game using a window based GUI toolkit like tkinter or pysimplegui.