For some odd reason my code was all working fine until I made a few changes which broke almost everything in the function. I've since removed said changes but it's still broken. It's saying the colon in this section is Invalid Syntax. In fact it's saying the same for every if statement as well as some of the comparison operators. - if difficulty == "e":
-
number_enemies -= 1
Thanks! I managed to run the code after a few changes. I saved it in txt because I couldn't upload it here in .py format. I began selecting all text and then pressing shift + tab twice; then, there was also a missing parentheses at the end of 11. This file, in .py format, ran ok. Sometimes, the error can be in a line other than the one indicated. Please let me know if you have any doubts. By the way, I changed the file encoding to UTF-8 due to an error that I got in here, but it may have been unnecessary. Please let me know if you still have any problems.
Maybe the only change you need to make is to add the missing parenthesis to your code.
5 5394
Hi, can you post all your code?
The whole function is quite long, but sure. It's supposed to create the enemies in a text game I'm working on. - # Randomly generates enemies
-
def create_enemies(difficulty, mode, current_location, battles):
-
-
# Clears enemies from the last battle
-
enemies = []
-
-
# List of possible names for the enemies to use
-
names = ["Aiden", "James", "Sam", "Aidan", "Brad", "Pavle", "Fuda", "David", "Andrew", "Harry", "Callum", "Tomasz", "Bazli", "Georgia", "Sheldon", "Legolas", "Aragorn", "Gimli", "Boromir", "Faramir", "Éomer", "Éowyn", "Treebeard", "Celeborn", "Galadrial", "Radagast", "Gandalf", "Merry", "Pippin", "Frodo", "Sam", "Bilbo", "Azog", "Gorkil", "Sharku", "Shagrat", "Gorbag", "Lurtz", "Tom Bombadil", "Goldberry"]
-
-
# Randomly decides how many enemies there will be
-
number_enemies = int(random.randint(2,5)
-
-
# 1 less enemy in Easy difficulty
-
if difficulty == "e":
-
number_enemies -= 1
-
# 1 more enemy in Hard difficulty
-
elif difficulty == "h":
-
number_enemies += 1
-
# 2 more enemies in Legendary difficulty
-
elif difficulty == "l":
-
number_enemies += 2
-
-
# The more battles you've had, the more enemies there will be
-
number_enemies += int((battles/100)*30)
-
-
# There will always be at least 2 enemies
-
if not (number_enemies >= 2):
-
number_enemies = 2
-
-
#Enemies are different at the boss battles
-
if mode == 2 and current_location.evil_final == True:
-
enemies = [Troll("Cave Troll"), Uruk("Uruk"), Wizard("Sauron"), Orc("Orc"), WargRider("Warg Rider"), Easterling("Easterling"), Goblin("Goblin 1"), Goblin("Goblin 2"), Goblin("Goblin 3")]
-
elif mode == 1 and current_location.good_final == True:
-
enemies = [Wizard("Gandalf"), Elf("Legolas"), Dwarf("Gimli"), Ranger("Aragorn"), Human("Boromir"), Hobbit("Frodo"), Hobbit("Sam"), Hobbit("Merry"), Hobbit("Pippin")]
-
else:
-
for z in range(number_enemies):
-
if mode == 1:
-
# Determines the class of the enemy
-
# 1/4 Goblin, 1/4 Orc, 1/8 Uruk, 1/8 Easterling, 3/24 Warg Rider, 2/24, Wizard, 1/24 Troll
-
enemy_class = random.randint(1, 24)
-
if enemy_class in range(1,6):
-
enemies.append(Goblin(names[random.randint(1,(len(names)-1))]))
-
if enemy_class in range(7,12):
-
enemies.append(Orc(names[random.randint(1,(len(names)-1))]))
-
if enemy_class in range(13,15):
-
enemies.append(Uruk(names[random.randint(1,(len(names)-1))]))
-
if enemy_class in range(16,18):
-
enemies.append(Easterling(names[random.randint(1,(len(names)-1))]))
-
if enemy_class in range(19,21):
-
enemies.append(WargRider(names[random.randint(1,(len(names)-1))]))
-
if enemy_class in range(22,23):
-
enemies.append(Wizard(names[random.randint(1,(len(names)-1))]))
-
if enemy_class == 24:
-
enemies.append(Troll(names[random.randint(1,(len(names)-1))]))
-
-
if mode == 2:
-
# Determines the class of the enemy
-
# 1/4 Hobbit, 1/4 Human, 1/8 Elf, 1/8 Dwarf, 3/24 Ranger, 2/24 Wizard, 1/24 Ent
-
enemy_class = random.randint(1, 24)
-
if enemy_class in range(1,6):
-
enemies.append(Hobbit(names[random.randint(1,(len(names)-1))]))
-
if enemy_class in range(7,12):
-
enemies.append(Human(names[random.randint(1,(len(names)-1))]))
-
if enemy_class in range(13,15):
-
enemies.append(Elf(names[random.randint(1,(len(names)-1))]))
-
if enemy_class in range(16,18):
-
enemies.append(Dwarf(names[random.randint(1,(len(names)-1))]))
-
if enemy_class in range(19,21):
-
enemies.append(Ranger(names[random.randint(1,(len(names)-1))]))
-
if enemy_class in range(22,23):
-
enemies.append(Wizard(names[random.randint(1,(len(names)-1))]))
-
if enemy_class == 24:
-
enemies.append(Ent(names[random.randint(1,(len(names)-1))]))
-
-
return enemies
Thanks! I managed to run the code after a few changes. I saved it in txt because I couldn't upload it here in .py format. I began selecting all text and then pressing shift + tab twice; then, there was also a missing parentheses at the end of 11. This file, in .py format, ran ok. Sometimes, the error can be in a line other than the one indicated. Please let me know if you have any doubts. By the way, I changed the file encoding to UTF-8 due to an error that I got in here, but it may have been unnecessary. Please let me know if you still have any problems.
Maybe the only change you need to make is to add the missing parenthesis to your code.
That missing parentheses... I put it there and suddenly everything works perfectly. Thank you so much!
You're welcome!
Best,
stdq
Sign in to post your reply or Sign up for a free account.
Similar topics
by: shank |
last post by:
1) I'm getting this error: Syntax error (missing operator) in query
expression on the below statement. Can I get some advice.
2) I searched ASPFAQ and came up blank. Where can find the "rules"...
|
by: evan.cooch |
last post by:
Greetings.
Suppose I have some function called "CheckIt" - some function to
validate form data before submitting it to e CGI script. Pretend the
name of the form is "TheForm".
If I use the...
|
by: Bradley Kite |
last post by:
Hi all.
I'm trying to diagnose/solve a problem with internet explorer, whereby
sometimes the form submits, and other times IE produces an 'invalid
syntax' error.
First, I have a form, and...
|
by: Mark Phanides |
last post by:
My ASP.NET application intermittantly (but always at same point) redirects to the 'Invalid Syntax Error' web page for some unknown reason.
I've created a ASP.NET application written in VB.NET with...
|
by: py |
last post by:
Hi,
I am running python 2.4.2 on win xp pro. I have the WMI module from
Tim Golden (http://tgolden.sc.sabren.com/python/wmi.html).
I have some code which does this...
MyScript.py...
|
by: ronrsr |
last post by:
no matter where I place this imported file,the statement after it in
the main program gets a syntax error, regardless of the syntax.
I think I may have changed something in this file, but I'm...
|
by: Hexer |
last post by:
Hi and good day to all...I am new to the C language and whenever I tried to run the program I made, it won't because it says it has an "expression syntax error in function main"..what I don't get is...
|
by: jonathanemil |
last post by:
Hello,
I am a 1st semester Computer Science student in a Python class. Our current assignment calls for us to read a list from a file, create a 2-dimensional list from the file, and check to see...
|
by: kakarot vegeta |
last post by:
There 's an invalid syntax error but i don't know what's wrong with it.
the error says
Invalid syntax: print variation_string
import itertools
variations = itertools.product('ab',...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |