Python Forum

Full Version: AND Boolean operator syntax error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello I am very new to python, any help is much appreciated.

I am having problems with line 48 the AND logical operator keeps throwing up an "invalid syntax" error. I have been trying for hours to rectify this but cannot find a solution. Can some one please help. Code shown on right and on line 48 elif current_health >50 and <70:
"""Made by 
My Adventure game"""

#Import

import random

#Variables

greeting = ("welcome to my adventure game.")
health = 200

difficulty = 1

#Calculations

monster_hit =int(random.randint(0,100)*difficulty)

monster_hit2 = int(random.randint(0,100)*difficulty)

current_health = health - (monster_hit + monster_hit2)

 

username = input("Enter your first name: ")
print()
print("-------------------------")
print()

print("Hello " + username.title() + ", " + greeting)


#use , (Comma)to concatenate int variable and stings only.   .title() capitalises the firt letter.

print()
print("Your starting health is " + str(health) + " points")    # convert int to str when no calculations are not being performed on the integer number 

print()
print("You have been hit by a monster for " + str(monster_hit + monster_hit2) + " points")
print()

print("After being hit, your health has dropped down to " + str(current_health)+ " points.")
print()

if current_health <=0:
    print("You have been killed by the monster, game over!")
    
elif current_health>50 and <70:
    print("Be careful your health is getting close to a dangerous point, it is " + str(current_health) +" Score value point")

else:
    print("You are on the verge of dying, be careful, your health score is" + str(current_health)+ "score value point")

print(monster_hit, monster_hit2)
print()
make line 48
elif 50 < current_health < 70:
if you must use and
elif current_health > 50 and current_health < 70:
but the first one is better
Thank you so much.

Working fine now.

All the best.
If you are using Pythor 3.6 or later you may consider taking advantage of f-strings which makes constructing strings more natural (and subjectively more beautiful). No commas or pluses and fragmented strings, just placeholders in one string:

>>> health = 200
>>> greeting = 'welcome to my adventure game.'
>>> username = 'bob'
>>> print(f"Hello {username.title()}, {greeting}")
Hello Bob, welcome to my adventure game.
>>> print(f"Your starting health is {health}")
Your starting health is 200