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?
#2
Please use python and output tags when posting code and results. I put them in for you this time. Here are instructions for doing it yourself next time.

The first problem is that you have getvalue serving two purposes: The name of the function and the name of the value it creates. Second, the value it creates exists only in the function. You need to return it to access it outside the function:

def getvalue(cpu):
    if cpu <= 300:
        value = 1
    return value

computer = getvalue(cpu)
Note that the easiest way to get a random value from 1 to 3 is random.randint(1, 3). Then you don't need a separate function. Especially because getvalue as set up now will cause an error if cpu is over 300.

Note that there is a tie whenever the human and computer choose the same, not just when they both choose 1 (human == computer). Also triple quotes (""") can be used to start and end a multi-line string.
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, 01:47 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,763 Sep-03-2019, 09:24 PM
Last Post: ichabod801
  Asking for help in my code for a "Guess the number" game. Domz 5 3,911 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