超怪的 for x in reversed(range(1,11)): print(x) print("happy new year!!") 輸出結果是 "D:\PyCharm 2023.3.4\python project\pythonProject\.venv\Scripts\python.exe" "D:\PyCharm 2023.3.4\python project\pythonProject\for_loop.py" 10 happy new year!! 9 happy new year!! 8 happy new year!! 7 happy new year!! 6 happy new year!! 5 happy new year!! 4 happy new year!! 3 happy new year!! 2 happy new year!! 1 happy new year!! Process finished with exit code 0
name = input("please key in your name")
for x in range( 0 , len(name) ):
print(name[x])
# 3. 逆序打印字母
# 给你一个字符串 "Python", 使用 for 循环逆序打印出这个字符串的每个字母。
print("练习三 :逆序打印字母")
text = "Python"
for t in reversed(text):
print(t)
# 6. 猜数字
# 有一个数字列表 numbers = [2, 4, 6, 8, 10, 12],使用 for 循环,当找到第一个大于 6 的数字时,立刻停止循环并打印出该数字。
print("练习六 :猜数字")
numbers = [2, 4, 6, 8, 10, 12]
for x in numbers:
if x > 6: # 找到第一个大于 6 的数字
print(x) # 打印出该数字 8
break # 立刻停止循环
請問.items()是甚麼意思呢?
發問請到六小時教學發問,統一在那邊回覆
可以理解为 字典中具体的“项”、“元素”,它由“键 key”与“值 value”组成。for key,value in dict.items() 就是把这些键值对分别依次赋值给变量key和value。
超怪的
for x in reversed(range(1,11)):
print(x)
print("happy new year!!")
輸出結果是
"D:\PyCharm 2023.3.4\python project\pythonProject\.venv\Scripts\python.exe" "D:\PyCharm 2023.3.4\python project\pythonProject\for_loop.py"
10
happy new year!!
9
happy new year!!
8
happy new year!!
7
happy new year!!
6
happy new year!!
5
happy new year!!
4
happy new year!!
3
happy new year!!
2
happy new year!!
1
happy new year!!
Process finished with exit code 0
沒錯啊 你用reveserd會倒著
@@CodeShiba 他和你倒數的方式不一樣
@@edisonshi19830729 大哥 沒幾行程式 看仔細點 = =
縮排要留意