Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python syntax error when using strings in variables

Code

import random
    
print("Witaj w grze papier, kamień i nożyczki")
    
player_1 = input("Wpisz nazwę gracza nr 1: ")
player_2 = input("Wpisz nazwę gracza nr 2: ")
choice_1 = (input("Wpisz wybór %s:",% (player_1)))

Problem

This code seems to be causing a syntax error and i dont know why

choice_1 = (input("Wpisz wybór %s:",% (player_1)))
                                            ^
SyntaxError: invalid syntax```

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Solution

Remove the comma after the string
choice_1 = (input("Wpisz wybór %s:" % (player_1)))

Other cleaner way (imo)

I would recommend you format the string differently, using the format() function.

choice_1 = input("Wpisz wybór {}:".format(player_1))

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading