简体   繁体   中英

Error or Syntax error in python Higher Lower Game

I am making a python Higher Lower game and I'm having a weird syntax error. Please help

import art
from game_data import data
from replit import clear
import random
print(art.logo)
Continue_Game = True
score = 0
while Continue_Game == True:
  def er():
    global A_value = data[random.randint(0,49)]
    global B_value = data[random.randint(0,49)]
    if A_value == B_Value:
      global B_value = game_data.data[random.randint(0,49)]
      if A_Value == B_Value:
        er()
    elif A_Value != B_Value:
      return
    else:
      er()
    er()
  A_Name = A_value["name"]
  A_Description = A_value["description"]
  A_Country = A_value["country"]
  A_Follow = A_value["follower_count"]
  B_Name = B_value["name"]
  B_Description = B_value["description"]
  B_Country = B_value["country"]
  B_Follow = B_value["follower_count"]
  print(f"Compare A: {A_Name}, a {A_Description}, from {A_Country}.")
  print(art.vs)
  print(f"Against B: {B_Name}, a {B_Description}, from {B_Country}.")
  User_follower = input("Who has more followers? Type 'A' or 'B': ")
  if User_follower.lower() == "a" and int(A_Follow) > int(B_Follow):
    clear()
    print(art.logo)
    score = score + 1
    print(f"You're right! Current score: {score}.")
    Continue_Game == True
  elif User_follower.lower() == "a" and int(A_Follow) < int(B_Follow):
    clear()
    print(art.logo)
    print(f"Sorry, that's wrong. Final score: {score}")
    Continue_Game == False
  elif User_follower.lower() == "b" and int(B_Follow) > int(A_Follow):
    clear()
    print(art.logo)
    score = score + 1
    print(f"You're right! Current score: {score}.")
    Continue_Game == True
  elif User_follower.lower() == "b" and int(B_Follow) < int(A_Follow):
    clear()
    print(art.logo)
    print(f"Sorry, that's wrong. Final score: {score}")
    Continue_Game == False

I'm getting a syntax error at line global A_value = data[random.randint(0,49)] The weird thing is that I don't get this error at line global B_Value = data[random.randint(0,49)] Have any Ideas to fix this error? I found out the red line or the error or where the console says the syntax error was at the = .

The global statement does not accept an expression (eg a = b ); it only accepts one or more identifiers (eg a ).

The reason you're only getting one syntax error is Python stopping parsing altogether at the first syntax error, but all of those global x = y lines are erroneous.

Split them, eg

global A_value, B_value
A_value = data[random.randint(0,49)]
B_value = data[random.randint(0,49)]

etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM