Python study notes TypeError: not all arguments converted during string formatting

foreword

It is inevitable to make some naive mistakes in learning python. In order to facilitate the learning of later people and their own progress, I sorted out the mistakes made in the learning process and wrote this document.

Table of contents

foreword

It is inevitable to make some naive mistakes in learning python. In order to facilitate the learning of later people and their own progress, I sorted out the mistakes made in the learning process and wrote this document.

question

TypeError: not all arguments converted during string formatting

example

Replenish


question

TypeError: not all arguments converted during string formatting


example

For example:

Take any positive integer n. If n is odd, change n to 3 * n + 1; if n is even, change n to n/2. If you repeat the operation, you will eventually get 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类型即可
'''

Replenish

I accidentally made a wrong operation in pycharm and wanted to go back to the previous step
- undo and undo: Ctrl + z, Ctrl + Shift + z

Guess you like

Origin blog.csdn.net/qq_43659681/article/details/124707872