文章目录
输入格式
1. 一行一个变量
n = int(input())
2. 一行确定个变量
a, b, c = map(int, input().split())
3. 一行未知个变量
arr = list(map(int, input().split()))
# 或者
arr = [int(i) for i in input().split()]
4. 二维数组的输入
n = int(input())
arr = []
for i in range(n):
arr.append(list(map(int, input().split())))
5. 未明确说明终止的输入
import sys
for n in sys.stdin:
if n == '\n':
break
print(n)
输出格式
1. 四舍五入保留两位小数
import math
if __name__ == "__main__":
# 3.14159
print("{:.2f}".format(math.pi)) # 3.14
print("{:.3f}".format(math.pi)) # 3.142
print(round(math.pi, 2)) # 3.14
print(round(math.pi, 3)) # 3.142
print('%.2f' % math.pi) # 3.14
print('%.3f' % math.pi) # 3.142
2. 仅保留两位小数,无需四舍五入
import math
if __name__ == "__main__":
# 3.14159
s = str(math.pi).split('.')
print(s[0] + '.' + s[1][:3]) # 3.141
3. 百分比格式输出
if __name__ == "__main__":
print('percent: {:.0%}'.format(0.3141592653589793)) # 31%
print('percent: {:.0%}'.format(0.2718281828459045)) # 27%
print('percent: {:.1%}'.format(0.3141592653589793)) # 31.4%
print('percent: {:.1%}'.format(0.2718281828459045)) # 27.2%
print('percent: {:.0f}%'.format(0.3141592653589793 * 100)) # 31%
print('percent: {:.0f}%'.format(0.2718281828459045 * 100)) # 27%
print('percent: {:.1f}%'.format(0.3141592653589793 * 100)) # 31.4%
print('percent: {:.1f}%'.format(0.2718281828459045 * 100)) # 27.2%
# 27.18%, 31.4%
print('{1:.2f}%, {0:.1%}'.format(0.3141592653589793, 0.2718281828459045 * 100))
IDLE调试方法
def dfs(n):
if n == 0 or n == 1:
return n
return dfs(n - 1) + dfs(n - 2)
if __name__ == "__main__":
for i in range(1, 11):
print('f({}) = {}'.format(i, dfs(i)))
1. 在.py
文件中,设置断点(清除断点)。
右键+Set Breakpoint
右键+Clear Breakpoint
2. 打开调式界面
s h e l l → D e b u g → D e b u g g e r shell \to Debug \to Debugger shell→Debug→Debugger
3. 运行.py
文件
快捷键:F5
4. 一些名词解释
Go
跳到断点处
Step
进入函数
Over
单步执行
Out
跳出函数
Quit
结束调试