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?
#1
Hi, I'm practicing coding using python and I'm working with this small project of mine. Im having issue running or calling the function into if else.

Target :
I want to generate a random between 0-900 and define a range,
if 0-300 then its 1 that represent rock, 301-600 is paper and 601-900 is scissors.. then player will select 1-3 for (rock paper scissors) if it matches tie. Thanks

Heres my code:
print ("Welcome to RPS GAME, Winning rules as follows: \n"
       +"Rock vs Paper = Paper Wins \n"
       +"Paper vs Scissor  = Scissor Wins \n"
       +"Scissor vs Rock = Rock Wins \n" )

#CPU Random
cpurange = range(300)
cpu = random.choice(cpurange)

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

#Human will select
human = int(input ("Pick 0-Rock, 1-Paper, 2-Scissors?: "))

if human == 1 and getvalue == 1:
  print ("TIE")

print ("##### RESULT ##### \n"
       +"Human: {}".format(human))
Result is not working if thinking if I properly calling the def getvalue function into below if/else statement.

Thanks
Reply


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

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