dimanche 5 décembre 2021

Run a function in the 'if statement'

When I run clear() as below it does not print the 'else' statement. It only works for the 'if' part. When I run it one indent outside, it clears without doing the print for both if and else. Please guide on where I should place it.

import random
from art import logo,vs
from game_data import data
from replit import clear

def game_question():
  return random.choice(data)

def format_data(account):
    account_name = account["name"]
    account_description = account["description"]
    account_country = account["country"]

    return f"{account_name}, {account_description}, {account_country}" 

  
def count(num_a, num_b):
    if num_a > num_b:
     return  "a"
    else:
      return "b"

win = 0

play_on = False

while not play_on:
  print (logo)

  account_a = game_question()
  account_b = game_question()

  if account_a == account_b:
    account_b = game_question()
  
  num_a = account_a["follower_count"]
  num_b = account_b["follower_count"]

  print(f"Account A : {format_data(account_a)}")
  print (vs)
  print(f"Compare to Account B: {format_data(account_b)}")

  ans = input("Which account has more followers? A or B: ").lower()

  if ans == count(num_a,num_b):
    win += 1
    print ("A win")

  else:
    print (f"Wrong. You lose. Win = {win}")
    play_on = True
  clear()  

Aucun commentaire:

Enregistrer un commentaire