Python Forum
needing some help to write some code for a game calculator
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
needing some help to write some code for a game calculator
#2
You should post your code. I'm don't really understand what you are asking for. Something like this maybe?
def damage_calc(damage, prev_damage):
    return max(prev_damage / 2, min(prev_damage * 2, damage))

print(damage_calc(220, 100))
print(damage_calc(25, 100))
print(damage_calc(75, 100))
Output:
200 50.0 75
This code clips the damage value to be in the range prev_damage / 2 to prev_damage * 2.
Reply


Messages In This Thread
RE: needing some help to write some code for a game calculator - by deanhystad - Jan-02-2024, 09:56 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  UART write binary code trix 3 380 Apr-28-2024, 04:57 PM
Last Post: deanhystad
  write code that resides in parent directory franklin97355 3 500 Apr-14-2024, 02:03 AM
Last Post: franklin97355
  Problem with my pong game code Than999 8 3,910 May-15-2022, 06:40 AM
Last Post: deanhystad
  Needing to Check Every Quarter Hour bill_z 10 3,160 Feb-09-2022, 07:23 PM
Last Post: menator01
  Calculator code issue using list kirt6405 4 2,342 Jun-11-2021, 10:13 PM
Last Post: topfox
  How to write a code with İF function? Aycaaxx 1 1,879 Nov-03-2020, 05:46 AM
Last Post: deanhystad
  Music Selection Game Code WyattH 3 2,495 Jul-20-2020, 11:16 AM
Last Post: ndc85430
  Beginner Code, how to print something after a number of turns (guessing game) QTPi 4 2,861 Jun-18-2020, 04:59 PM
Last Post: QTPi
  Hi Guys, please help me to write SAS macro parameter equivalent code in Python Manohar9589 2 2,656 Jun-14-2020, 05:07 PM
Last Post: Larz60+
  Noob needing guidance.... bako 0 1,886 Mar-29-2020, 06:55 PM
Last Post: bako

Forum Jump:

User Panel Messages

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