赞
踩
目录
在学习python中难免犯下一些幼稚的错误,为了方便后来人的学习与自己的进步,整理了在学习过程中犯下的错误,写下此篇文档。
TypeError: not all arguments converted during string formatting
例如:
任意取一个正整数n。如果n是奇数,则把n变为3 * n +1;如果n是偶数,则把n变为n / 2。不断重复操作,则最终一定会得到1。
- '''
- 2022-5-11
- '''
-
- a = int(input("输入一个数字:"))
- step = 0
- while a != 1:
- if a % 2 == 0:
- a = a / 2
- else:
- a = 3 * a + 1
- step += 1 #记录计算的步数
- print("步数:",step)
- '''
- python3.x 中 input()函数返回的是一个String类型的数据
- 此代码中,取余符号两边数值类型应该一样,通过int()函数将String类型i转化为int类型即可
- '''
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
pycharm中不小心进行了错误的操作,想要回到前一步操作的时候
- 撤销与反撤销操作:Ctrl + z,Ctrl + Shift + z
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。