程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Random toolkit for Python learning notes

編輯:Python

Catalog

random tool kit

print function


random tool kit

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 function

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 .


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved