Python Forum
Code: Creating a basic python game?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Code: Creating a basic python game?
#4
Your current code has syntax errors. In the first version on line 4, you are checking if cpu equals a range object; this is failing for two reasons. First, cpu is a number, not a range object so it will never be equal. The intent is to check if cpu is within the range, not that it's equal to the range. There are two ways to write this:

def getvalue(cpu):
   if cpu <= 300:
       value = 1
   elif cpu in range(301,600):
       value = 2
   else: value = 3

   return value
or

def getvalue(cpu):
   if cpu <= 300:
       value = 1
   elif 301 <= cpu <= 600:
       value = 2
   else: value = 3

   return value
On a side note, a random number between 1 and 900 is excessive. You truly only need one through three since there are only three possibilities.
Reply


Messages In This Thread
Code: Creating a basic python game? - by searching1 - Nov-12-2018, 12:47 AM
RE: Code: Creating a basic python game? - by stullis - Nov-12-2018, 02:25 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Need some help creating a word game wthiierry 4 2,557 Nov-01-2022, 12:29 PM
Last Post: perfringo
  problem on creating a small game nayo43 5 2,866 Dec-13-2020, 01:03 PM
Last Post: jefsummers
  [split] help me make this code better please (basic) Rustam 2 2,313 Jun-19-2020, 01:27 PM
Last Post: Rustam
  restarting game code zyada7med 5 4,764 Sep-03-2019, 09:24 PM
Last Post: ichabod801
  Asking for help in my code for a "Guess the number" game. Domz 5 3,912 Aug-14-2019, 12:35 PM
Last Post: perfringo
  Basic Quiz/Game searching1 10 5,885 Nov-18-2018, 03:58 AM
Last Post: ichabod801
  Creating code to make up to 4 turtle move simultaneously in a random heading J0k3r 3 5,618 Mar-05-2018, 03:48 PM
Last Post: mpd
  Basic code HGOBOI 2 2,850 Mar-05-2018, 12:02 PM
Last Post: Larz60+
  Lots of code. Creating modules jwhenson1990 2 2,888 Oct-13-2017, 08:31 AM
Last Post: gruntfutuk
  Hangman-Game (German code) .. Unkreatief 1 3,765 Mar-22-2017, 10:30 AM
Last Post: Kebap

Forum Jump:

User Panel Messages

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