單回圈實作一行十個★
# 方法一
i = 0
while i < 10:
print("★", end="")
i += 1
print()
# 方法二(通過變數的形式實作)
i = 0
str_var = ""
while i < 10:
strvar += "★"
i += 1
print(strvar)
單回圈實作十個換色★
i = 1
while i <= 10:
if i % 2 == 1:
print("★", end="")
else:
print("☆", end="")
i += 1
print()
單回圈實作十行十列★
i = 1
while i <= 100:
print("★", end="")
if i % 10 == 0:
print()
i += 1
print()
單回圈實作隔列換色★
i = 1
while i <= 100:
if i % 2 == 0:
print("★", end="")
else:
print("☆", end="")
if i % 10 == 0:
print()
i += 1
print()
單回圈實作隔行換色★
i = 0
while i < 100:
if i // 10 % 2 == 0:
print("★", end="")
else:
print("☆", end="")
if i % 10 == 9:
print()
i += 1
print()
單回圈輸出1-100所有奇數
i = 1
while i <= 100:
if i % 2 == 1:
print(i)
i += 1
單回圈輸出1-100所有偶數
i = 1
while i <= 100:
if i % 2 == 0:
print(i)
i += 1
單回圈實作國際象棋棋盤效果
i = 0
while i < 64:
# 判斷當前是奇數行還是偶數行
if i // 8 % 2 == 0:
if i % 2 == 0:
print("□", end="")
else:
print("■", end="")
else:
if i % 2 == 0:
print("■", end="")
else:
print("□", end="")
# 第八個方塊換行
if i % 8 == 7:
print()
i += 1
折紙求高度
如題:我國最高山峰是珠穆朗瑪峰:8848m,我現在有一張足夠大的紙張,厚度為:0.01m,請問,折疊多少次,就可以保證厚度不低于珠穆朗瑪峰的高度?
height = 0.01
times = 1
while True:
if height * 2 ** times >= 8848:
print(times)
break
times += 1
籃球彈跳
如題:籃球從十米的位置向下掉落,每一次掉落都是前一次的一半,問彈跳十次之后籃球的高度是多少?
times = 1
while True:
height /= 2
if times == 10:
print(height)
break
times += 1
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/188877.html
標籤:Python
