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?
#5
Also note that if a value is not 300 or less, then you already know it's over 300:

def getvalue(cpu):
    if cpu <= 300:
        value = 1
    elif cpu <= 600:
        value = 2
    else:
        value = 3
    return value
Of course, since it is even ranges, you could just divide (random.randint(1, 900) // 3 + 1).

But as I implied and stulis clarified, generating 1-900 and then shrinking it down to 1-3 is overkill. Unless that is part of the assignment?

Have you done dictionaries yet? That's the best way to handle determining who won rock-paper-scissors in my experience.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
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 ichabod801 - Nov-12-2018, 02:35 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  problem on creating a small game nayo43 5 2,964 Dec-13-2020, 01:03 PM
Last Post: jefsummers
  [split] help me make this code better please (basic) Rustam 2 2,384 Jun-19-2020, 01:27 PM
Last Post: Rustam
  restarting game code zyada7med 5 4,888 Sep-03-2019, 09:24 PM
Last Post: ichabod801
  Asking for help in my code for a "Guess the number" game. Domz 5 4,008 Aug-14-2019, 12:35 PM
Last Post: perfringo
  Basic Quiz/Game searching1 10 6,029 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,751 Mar-05-2018, 03:48 PM
Last Post: mpd
  Basic code HGOBOI 2 2,912 Mar-05-2018, 12:02 PM
Last Post: Larz60+
  Lots of code. Creating modules jwhenson1990 2 2,937 Oct-13-2017, 08:31 AM
Last Post: gruntfutuk
  Hangman-Game (German code) .. Unkreatief 1 3,820 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