Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1066791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:04:03+00:00 2026-05-16T20:04:03+00:00

Assume you have written a new function that checks to see if your game

  • 0

Assume you have written a new function that checks to see if your game character has any life left. If the character does not have any life left, the function should print ‘dead’, if it has less than or equal to 5 life points left the function should print ‘almost dead’, otherwise it should print ‘alive’.

am_i_alive(): 
    hit_points = 20
    if hit_points = 0: 
        print 'dead'
    else hit_points <= 5: 
        print 'almost dead'
    else: 
        print 'alive'

am_i_alive()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T20:04:04+00:00Added an answer on May 16, 2026 at 8:04 pm
    def am_i_alive(): 
        hit_points = 20
        if hit_points == 0: 
            print 'dead'
        elif hit_points <= 5: 
            print 'almost dead'
        else: 
            print 'alive'
    
    am_i_alive()
    
    1. You need the def keyword to define a function.
    2. You need to use == and not = for comparisons.
    3. You chain if statements using elif.

    other than that, it looks good. As in correct and will compile. It will always yield the same value though.

    A better way to do it is:

    def am_i_alive(hit_points): 
        if hit_points == 0:
            print 'dead'
        elif hit_points <= 5: 
            print 'almost dead'
        else: 
            print 'alive'
    
    am_i_alive(20)
    am_i_alive(3)
    am_i_alive(0)
    

    Here, we are passing an ‘argument’ to the function. we call it with am_i_alive(x) where x can be any number. In the code for the function am_i_alive, whatever we put in place of x becomes the value referred to by hit_points.

    A function can take two arguments as well. (in fact, up to 255 arguments)

    def am_i_alive(hit_points, threshold): 
        if hit_points == 0:
            print 'dead'
        elif hit_points <= threshold: 
            print 'almost dead'
        else: 
            print 'alive'
    
    am_i_alive(20, 5)
    am_i_alive(3, 2)
    am_i_alive(0, 10)
    

    Can you understand what the last version does?

    I didn’t read it because python is not my first language, but I’m told that this is a very good introduction to python and programming.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume i have a custom Windows application written in C#. This application has only
Let's assume I have a framework written in Java and some C++ code which
Assume you have a function read_key and normally it does some stuff. You someone
I have written the following function which adds an event listener and registers the
I have written a game (I'll give it the name Gamer) in which I
I have an application behaving like autorefresh. It checks emails, new videos, jokes, etc.
I have written a fairly large program in Fortran 90. It has been working
If I have a usercontrol (in Silverlight) that I've written, that uses XAML to
I have recently written a socket server in PHP that will be handling communication
I have a web app that uses some jars written by me. My challenge

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.