Python Forum
AND Boolean operator syntax error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AND Boolean operator syntax error
#1
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()
Reply
#2
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Thank you so much.

Working fine now.

All the best.
Reply
#4
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
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Syntax error for "root = Tk()" dlwaddel 15 1,011 Jan-29-2024, 12:07 AM
Last Post: dlwaddel
Photo SYNTAX ERROR Yannko 3 334 Jan-19-2024, 01:20 PM
Last Post: rob101
  Syntax error while executing the Python code in Linux DivAsh 8 1,451 Jul-19-2023, 06:27 PM
Last Post: Lahearle
  Code is returning the incorrect values. syntax error 007sonic 6 1,136 Jun-19-2023, 03:35 AM
Last Post: 007sonic
  syntax error question - string mgallotti 5 1,251 Feb-03-2023, 05:10 PM
Last Post: mgallotti
  Syntax error? I don't see it KenHorse 4 1,194 Jan-15-2023, 07:49 PM
Last Post: Gribouillis
  Syntax error tibbj001 2 847 Dec-05-2022, 06:38 PM
Last Post: deanhystad
  Python-for-Android:p4a: syntax error in main.py while compiling apk jttolleson 2 1,777 Sep-17-2022, 04:09 AM
Last Post: jttolleson
  Mysql Syntax error in pymysql ilknurg 4 2,289 May-18-2022, 06:50 AM
Last Post: ibreeden
  Solving equation equal to zero: How to resolve the syntax error? alexfrol86 3 1,894 Feb-21-2022, 08:58 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020