I wrote this in Python 3, but how can I prevent the user from entering a string?
x = int(input("If you want to play with computer, click 0. If you want to play with your friend, click 1. "))
You can add an if statement with the isnumeric method of str type before the integer cast, like that:
x = input('Enter a number: ')
if x.isnumeric(): # Returns True if x is numeric, otherwise False.
int(x) # Cast it and do what you want with it.
else: # x isn't numeric
print('You broke the rules, only numeric is accepted.')