pythonループ練習問題
54397 ワード
出力1~100偶数と
---------------------------------------------------------------------------------------------
for i in range(0,101,2):
print(i,end="\t")
--------------------------------------------------------------------------------------------
10 10 *
for i in range(1,11):
for j in range(1,11):
print("*",end="")
print()
---------------------------------------------------------------------------------------------------------
for i in range(1,7):
for j in range(1,i):
print("*",end="")
print()
---------------------------------------------------------------------------------------------------------
for i in range(1,10):
for j in range(1,i):
print(j,"*",i,"=",j*i,end="\t")
print()
---------------------------------------------------------------------------------------------------------
a=0
b=1
c=a+b
print(a)
print(b)
while c<1000:
print(c)
a=b
b=c
c=a+b
a=b=1
print(a,b)
for i in range(1,7):
print(a+b)
c=a # a c ( )
a=b # a
b=c+b #
a=b=1
print(a,b)
for i in range(1,7):
print(a+b)
a,b=b,a+b# python
---------------------------------------------------------------------------------------------
3
for i in range(1,6):
sum=0
for j in range(1,4):
socer=input(" %d ",str(j)," :"%i)# j %d
socer=int(socer)
sum=sum+socer
sum=sum/j
print(" ",i," ",sum)
print()
#
for i in range(1,6):
socer=0
for j in range(1,4):
socer+=input(" %d ",str(j)," :"%i)# j %d
print(" ",i," ",socer/3)
----------------------------------------------------------------------------------------------------------
for i in range(0,8):
for e in range(8,i,-1):
print(" ",end='')
for j in range(1,i+(i+2)):
print("*",end='')
print()
for i in range(1,9):
print(' '*(8-i),"*"*(2*i-1))
-----------------------------------------------------------------------------------------------------------
, 1-10
tag=True
a=int(input(" :"))
for i in range(1,11):
if i%a==0:
tag=False
print(i)
break
if tag==True:
print(" ")
python
a=int(input(" :"))
for i in range(1,11):
if i%a==0:
tag=False
print(i)
break
else:
print(" ")
for...else: break , if, else
-------------------------------------------------------------------------------------------------------------
while: while
, y ,
tag='y'
while tag=="y":
print(" ")
tag=input(' ?y/n')
-----------------------------------------------------------------------------------------------------------
1-10
a=0
while a<11:
print(a)
a=a+1
-----------------------------------------------------------------------------------------------
, , 0 、
sum=0
while True:
a=int(input(" :"))
if a==0:
print(" ")
break
else:
sum+=a
print(" ",sum)
------------------------------------------------------------------------------------------------------------
:1、2、3、4, ? ?
cont=0
for i in range(1,5):
for j in range(1,5):
for a in range (1,5):
if i!=j and j!=a and a!=i:
print(i,j,a)
cont=cont+1
print(cont)
---------------------------------------------------------------
1-100 :
for i in range(2,101):
a=True
for j in range(2,i-1):
if(i%j==0):
a=False
break
if a==True:
print(i)
for i in range(2,101):
j=2
while j<=i:
if i%j==0:
break
j+=1
if j<i:
continue
else:
print(i,end="\t")
--------------------------------------------------------
,
num1=int(input(" "))
num2=int(input(" "))
for i in range(num1,0,-1):
if num1%i==0 and num2%i==0:
print(" ",i)
print(' ',(num1*num2)/i)
break
---------------------------------------------------------------------------------------------
======================================== a. b. c. d. =========================================
, , ,
xxx,
db={} prompt=''' ======================================== a. b. c. d. ========================================= ''' while True: choice=input(prompt) print(' [%s]'%choice) if choice not in ('abcd'): print(" ") else: if choice =="a": prompt1=' :' while True: name=input(prompt1) if name in db: prompt1=' ' continue else: break pwd=input(' :') db[name]=pwd elif choice=='b': name=input(" :") pwd=input(" :") password=db.get(name) if password==pwd: print(' %s, '%name) break else: print(" ") elif choice=="c": print(" ") break elif choice=="d": name = input(" :") pwd = input(" :") password = db.get(name) if password == pwd: pwd1=input(" ") db[name]=pwd1 else: input(" ")