#基本输出函数 print(value1,value2,...) a = 100#python变量名区分大小写 print()#空行 print(1,2,3) #1 2 3 print(a) #100 print("\np\ny\nt\nh\no\nn\n") #同下 print(""" p y t h o n """)
#流程控制 num = 19 if num >= 20: print(">=20") else: print("<20") # <20
score = 93 if score >= 100: print("[100,无穷)") elif score >95: print("(95,99]") else: print("(-无穷,95]") # (-无穷,95] for i in range(5): print(i) # 0 1 2 3 4 for i in range(1,5): print(i) # 1 2 3 4 for i in range(1,5,2): print(i) # 1 3 n = 1 while(n<5): print(n) n += 1 else: print("100") # 1 2 3 4 100 for n in range(1,10): for m in range(1,n+1): print(f"{n}*{m}={n*m}",end=" ") #乘法口诀 print() n = 1 while n<=9: m = 1 while m<=n: print(f"{m}*{n}={m*n}",end=" ") #乘法口诀 m+=1 n+=1 print()
#break 结束整个循环 for i in [1,2,3,4,5]: if i == 3: break print(i) #1 2 #continue 跳过本层循环 for i in [1,2,3,4,5]: if i == 3: continue print(i) #1 2 4 5
num = random.randint(1,100) whileTrue: ans = int(input("输入1~100:")) if ans == num: print("bingo!") break elif ans > num: print("大了!") else: print("小了!")