单循环实现一行十个★
<code class="language-python"># 方法一 i = 0 <a href="https://www.gaodaima.com/tag/while" title="查看更多关于while的文章" target="_blank">while</a> i < 10: <a href="https://www.gaodaima.com/tag/print" title="查看更多关于print的文章" target="_blank">print</a>("★", end="") i += 1 print() # 方法二(通过变量的形式实现) i = 0 str_var = "" while i < 10: strvar += "★" i += 1 print(strvar) </code>
www#gaodaima.com来源gaodai#ma#com搞*!代#%^码$网搞代码
单循环实现十个换色★
<code class="language-python">i = 1 while i <= 10: if i % 2 == 1: print("★", end="") else: print("☆", end="") i += 1 print() </code>
单循环实现十行十列★
<code class="language-python">i = 1 while i <= 100: print("★", end="") if i % 10 == 0: print() i += 1 print() </code>
单循环实现隔列换色★
<code class="language-python">i = 1 while i <= 100: if i % 2 == 0: print("★", end="") else: print("☆", end="") if i % 10 == 0: print() i += 1 print() </code>
单循环实现隔行换色★
<code class="language-python">i = 0 while i < 100: if i // 10 % 2 == 0: print("★", end="") else: print("☆", end="") if i % 10 == 9: print() i += 1 print() </code>
单循环输出1-100所有奇数
<code class="language-python">i = 1 while i <= 100: if i % 2 == 1: print(i) i += 1 </code>
单循环输出1-100所有偶数
<code class="language-python">i = 1 while i <= 100: if i % 2 == 0: print(i) i += 1 </code>
单循环实现国际象棋棋盘效果
<code class="language-python">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 </code>
折纸求高度
如题:我国最高山峰是珠穆朗玛峰:8848m,我现在有一张足够大的纸张,厚度为:0.01m。请问,折叠多少次,就可以保证厚度不低于珠穆朗玛峰的高度?
<code class="language-python">height = 0.01 times = 1 while True: if height * 2 ** times >= 8848: print(times) break times += 1 </code>
篮球弹跳
如题:篮球从十米的位置向下掉落,每一次掉落都是前一次的一半,问弹跳十次之后篮球的高度是多少?
<code class="language-python">times = 1 while True: height /= 2 if times == 10: print(height) break times += 1 </code>