Pythonベースの乱数、エスケープ文字、whileループ、付与演算子などのテスト
説明:以下のコードはpycharmでテストに直接コピーできます.
#
# , , , ,
import random
"""
python
(1), (2), (3)
python , , - - -
import random
"""
player = int(input(" (1), (2), (3):"))
computer = random.randint(1,3) # 1 3 1 3, : ,
print(" %d - : %d" % (player,computer))
# if 8
if ((player == 1 and computer == 2)
or (player == 2 and computer == 3)
or (player == 3 and computer == 1)):
print(" ")
elif player == computer:
print(" ")
else:
print(" ")
"""
while :while
"""
# 5 hello python
i = 1
while i <= 5:
#
print("Hello Python")
#
i = i + 1
print(" ,i=%d" % i)
"""
python
=: c=a+b a+b c
+=: c+=a c=c+a
-=: c-=a c=c-a
*=: /=:
//=: c//=a c =c//a
%= : ( ) c%=a c = c%a
**=: c**=a c=c**a
python : , 0
"""
# 0 100
j = 0
all_num = 0
while j <= 100:
all_num = all_num + j
j += 1
print(" :%d" % all_num)
# 0-100
t = 0
ou_num = 0
while t <= 100:
o = t % 2
if o == 0:
ou_num += t
t += 1
print(" : %d" % ou_num)
"""
break continue
break: , ,
continue: ,
break continue
"""
m = 0
while m < 10:
print(m)
m += 1
if m == 4: # m == 4
break
print(" ")
# continue
a = 0
while a< 10:
if a == 4:
print("a %d ,continue " % a)
a += 2
# , ,
continue
print("a :%d" % a)
a += 1
#
g = 1;
while g <= 5:
print("*" * g)
g += 1
"""
,print ,
, print , end=""
"" print ,
"""
print("*",end=" ")
print("print ")
row = 1
while row <= 5:
col = 1
while col <= row:
print("*" , end="")
col += 1
#
print()
row += 1
#
rows = 1
while rows <= 9:
cols = 1
while cols <= rows:
print("%d*%d=%d\t" %(cols,rows,rows*cols),end="" )
cols += 1
print()
rows += 1
"""
:
\t ,
\\
\'
\" \t
\r
"""
print("hello
python")
print("hello \" hello \' hello \\ hello")