Python Forum
Learning Python, newbie question about strings and evaluation
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Learning Python, newbie question about strings and evaluation
#1
Hi all,

I'm going through an online course to learn Python3. Am getting on fine but I seem interested in finding not simply a "correct" answer that the site will parse and accept, I seem interested in thinking about the most efficient ways to solve any particular problem.

My current task is to code a simple game of "rock, paper, scissors". I'd like to achieve this by, in the second part of my code, taking inputs from both players, store them as variables (input1, input2), and then use an if: test to find the winner. Seems sound in principle but what I do not know and do not know if it's possible is the following:

It seems that if I write "Rock > "Scissors" ... "Paper" > "Rock" and so on, to have the If: f statement evaluate each input and calculate the winner correctly in fact Python simply returns boolean values for these statements irrespective of my declarations. Is there a simple method of declaring these strings in some way that I can then state e.g. "This" > "That", or is this simply not possible? I realise there are other ways to solve the problem, but curious about whether the above approach could be made to work.
Reply


Messages In This Thread
Learning Python, newbie question about strings and evaluation - by new_learner_999 - Feb-17-2018, 03:34 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How is pandas modifying all rows in an assignment - python-newbie question markm74 1 712 Nov-28-2023, 10:36 PM
Last Post: deanhystad
  newbie question - can't make code work tronic72 2 708 Oct-22-2023, 09:08 PM
Last Post: tronic72
  Newbie question about switching between files - Python/Pycharm Busby222 3 634 Oct-15-2023, 03:16 PM
Last Post: deanhystad
  UndefinedEnvironmentName: 'extra' does not exist in evaluation environment EarthAndMoon 3 1,713 Oct-09-2023, 05:38 PM
Last Post: snippsat
  Trying to understand strings and lists of strings Konstantin23 2 787 Aug-06-2023, 11:42 AM
Last Post: deanhystad
  Newbie.... run for cover. OpenCV question Stevolution2023 2 997 Apr-12-2023, 12:57 PM
Last Post: Stevolution2023
  numpy newbie question bcwilly_ca 4 1,212 Feb-10-2023, 05:55 PM
Last Post: jefsummers
  Python newbie laleebee 2 1,346 May-24-2022, 01:39 PM
Last Post: laleebee
  Splitting strings in list of strings jesse68 3 1,801 Mar-02-2022, 05:15 PM
Last Post: DeaD_EyE
  Conditional evaluation stsxbel 7 3,551 Jun-13-2021, 08:27 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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