Sorry if this is a stupid easy fix, I am VERY new to coding in general
So I am trying to code a rock paper scissors game but my result isn’t coming out right and idk why
My Code:
import random
while True:
user_action = input("Enter a choice (rock, paper, scissors): ")
possible_actions = ["rock", "paper", "scissors"]
computer_action = random.choice(possible_actions)
print("computer chose {computer_action}.")
and then it responds with this when I run
computer chose {computer_action}.
and it should fill in {computer_action} with a random choice but its not and idk why
Well, yes; but if the problem is an old version of Python that doesn’t support this feature, then a generic message would very much be expected. (And even the most recent versions still have SyntaxErrors that say only invalid syntax most of the time; they just have better highlighting.)
OP: you need to be using at least version 3.6 for this feature. You can check what version of Python is running the script, from within the script, like so:
import sys
print(sys.version)
If you have an old version of Python it is strongly recommended to update (do not try to remove any version of Python that was already on your computer when you got it). The oldest version that is still supported is 3.8. For details:
In the future, please show complete error messages by copying and pasting the entire stack trace (i.e., starting from the line that says Traceback (most recent call last): until the end), and format them the same way as the code (they’re designed to look right in a terminal).
The “F” should be placed to the left of the string.
Given that English is read from left-to-right, the word “before” is also an anathema. Even the manual says " begin a string with f or F before the opening quotation mark or triple quotation mark". Compared with (say): “A formatted-string is indicated with an f or F character-prefix, followed by a string-literal delimited by quotation-marks in the usual fashion”.
Fair point. But it will still show every other line as usual, including the actual traceback with the corresponding line of code, all with the appropriate whitespace to look right when formatted as multi-line code.