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
#9
yes, that are correct, my logic was confused. However I've come to the conclusion that it's not possible to do this at all in the way I'd assumed. I'm not saying I'm right in this - after all, this would seem a classic rookie error "It can't be done!" - but I'll say why just in case there's more I can learn.

I reduced my central problem to trying to do this - which produces an error of course, because presumably this is not allowed:

def reassign(x, y):
    return x > y = True

reassign(5, 6) #my intention above is to produce the result 5 > 6 == True so that e.g. "rock" beats "scissors"

print(reassign(5, 6))
This is where the idea currently fails. I'm trying to assign some 'order of truth' to "rock", "paper" and "scissors". As far as I'm currently aware making a comparison does not allow me to do this. Of course I can define a function which takes

pn = input("Player n choice: ")
and compare them, but then I end up putting the same 'long hand' if/elif inside the function that are my current solution where no function is involved at all.
Reply


Messages In This Thread
RE: Learning Python, newbie question about strings and evaluation - by new_learner_999 - Feb-18-2018, 09:34 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Can you explain the strings in Python ebn852_pan 3 158 May-19-2024, 08:36 AM
Last Post: Pedroski55
  How is pandas modifying all rows in an assignment - python-newbie question markm74 1 765 Nov-28-2023, 10:36 PM
Last Post: deanhystad
  newbie question - can't make code work tronic72 2 742 Oct-22-2023, 09:08 PM
Last Post: tronic72
  Newbie question about switching between files - Python/Pycharm Busby222 3 676 Oct-15-2023, 03:16 PM
Last Post: deanhystad
  UndefinedEnvironmentName: 'extra' does not exist in evaluation environment EarthAndMoon 3 1,783 Oct-09-2023, 05:38 PM
Last Post: snippsat
  Trying to understand strings and lists of strings Konstantin23 2 848 Aug-06-2023, 11:42 AM
Last Post: deanhystad
  Newbie.... run for cover. OpenCV question Stevolution2023 2 1,030 Apr-12-2023, 12:57 PM
Last Post: Stevolution2023
  numpy newbie question bcwilly_ca 4 1,247 Feb-10-2023, 05:55 PM
Last Post: jefsummers
  Python newbie laleebee 2 1,389 May-24-2022, 01:39 PM
Last Post: laleebee
  Splitting strings in list of strings jesse68 3 1,843 Mar-02-2022, 05:15 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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