Python Forum
Problem with Basic Rock Paper Scissors code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with Basic Rock Paper Scissors code
#3
(Sep-13-2019, 12:40 PM)ichabod801 Wrote:
  • Your randomization isn't working because randint returns an int, and you are comparing that to strings.
  • Better would be random.choice('rps'), it just gives you what you need in one line.
  • Globals lead to confusing and hard to maintain code. Pass parameters and assign return values. See the function tutorial for more details.
  • For multiple comparisons in is often [the best choice: if rps not in ('r', 'p', 's'):.
  • RPS is a great place to learn dictionaries instead of complicated if/elif/else:
 wins = {'r': 's', 'p': 'r', 's': 'p'} if rps = ai: print('tie') elif wins[ai] == rps: print('win') else: print('loss') 

Hello sir!
You said I was comparing an integer to a string, and that was causing problem. This has happened with me before. I'm almost too new, could you please tell how to compare integer to integer? Please just send me the correction of that part, since I don't know how to do any other corrections you told. Thank you!
Reply


Messages In This Thread
RE: Problem with Basic Rock Paper Scissors code - by BirinderSingh - Sep-13-2019, 12:51 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Rock Paper Scissors Project in Python ankitdixit 8 4,876 Feb-23-2024, 03:14 PM
Last Post: DPaul
  Trying to create a visual rock paper scissors game urmom33 1 1,042 Dec-03-2022, 09:12 PM
Last Post: deanhystad
  Rock paper scissors in python with "algorithm" Agat0 23 6,094 Mar-01-2022, 03:20 PM
Last Post: Agat0
  Problem restricting user input in my rock paper scissors game ashergreen 6 4,641 Mar-25-2021, 03:54 AM
Last Post: deanhystad
  Odd behavior with Rock Paper Scissor game DustinKlent 2 1,955 Aug-27-2020, 03:55 PM
Last Post: DustinKlent
  List index out of range error when attempting to make a basic shift code djwilson0495 4 3,010 Aug-16-2020, 08:56 PM
Last Post: deanhystad
  Writing a basic shift code djwilson0495 2 2,280 Aug-16-2020, 01:52 PM
Last Post: djwilson0495
  Trying to implement Best of 3 logic in rock paper scissors game ShAhCh 5 3,380 May-11-2020, 04:31 PM
Last Post: ShAhCh
  Rock Paper Scissors with dictionaries ewgreht 2 3,906 May-01-2020, 03:19 PM
Last Post: deanhystad
  Rock, Paper, Scissors.. Help..hidden bug xxunknownxx 4 2,681 Mar-19-2020, 02:46 AM
Last Post: jefsummers

Forum Jump:

User Panel Messages

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