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?
#3
@ichabod801, Thanks for your reply.

Standard procedure of posting of codes is noted.

1. While the given command works, But I would like to if to define the function is we need to create a variable "computer"? (Will research about funnction tho.)

2. random.randint(1, 3) - I this case its 1 to 3 only but i need 0 - 900 then I divide it to 3 for 3 choices (rock,paper,scissor). Should I use (1,900)?

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

computer = getvalue(cpu)

if human == 1 and computer == 1:
          print ("TIE-ROCK")
elif human == 2 and computer == 2:
          print ("TIE-PAPER")
Currently its not working when more than 300 as stated above.

Tried using this, but completely blind on what will is use to get the range of 300 to 600 and assign a value of 2.. Checking on conjunction operator
#CPU Random
rndm = random.randint(301,600)

def getvalue(rndm):
   if rndm <= 300:
       value = 1
   elif rndm >=301 and <=600:
       value = 2
   elif rndm <= 601:
       value = 3
   return value
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 searching1 - Nov-12-2018, 02:17 AM

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