Catalog
random tool kit
print function
Use import random After the package is imported, its internal functions can be used .
Case study :
import random
player = int(input(" Please enter scissors (1) stone (2) cloth (3):"))
comp = random.randint(1, 3)
if ((player == 1 and comp == 3)
or (player == 2 and comp == 1)
or (player == 3 and comp == 2)):
print(" Is too weak , Computer brother ")
elif (player == 1 and comp == 1) or (player == 2 and comp == 2) or (player == 3 and comp == 3):
print(" It's a draw ")
else:
print(" Ah ah , I am lost ")
print(" Computer brother :%d, user :%d" % (comp, player))
print("*", end=" ")
print("*")
# print Will automatically add a newline after it . If you do not need to wrap lines, you can use end=" " To set up
So the two stars will run in one line , here end You can separate them without spaces , It doesn't matter if it's separated , No impact on operation .