TypeError not all arguments converted during string formatt

1、错误描述

>>> a=1;
>>> b=1;
>>> for i in range(1,21):
	print(‘121d %121d‘ % (a,b));
	if(i%3==0):
		a=a+b ;
		b=a+b;

Traceback (most recent call last):
  File "<pyshell#23>", line 2, in <module>
    print(‘121d %121d‘ % (a,b));
TypeError: not all arguments converted during string formatting
>>> 

2、错误原因

由错误提示可知,并不是所有的参数都可以转换成字符串格式

3、解决办法

>>> a=1;
>>> b=1;
>>> for i in range(1,21):
	print(‘%12ld %12ld‘ % (a,b));
	if((i%3)==0):
		print("");
		a=a+b;
		b=a+b;

           1            1
           1            1
           1            1

           2            3
           2            3
           2            3

           5            8
           5            8
           5            8

          13           21
          13           21
          13           21

          34           55
          34           55
          34           55

          89          144
          89          144
          89          144

         233          377
         233          377
>>> 

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

原文地址:https://www.cnblogs.com/odejsjhshw/p/10387328.html

时间: 2024-08-07 18:32:11

TypeError not all arguments converted during string formatt的相关文章

关于Python的TypeError not all arguments converted during string formatting

前言 在把yolov3的cfg文件转换为model_defs时,我忘记把str类型转换成int了,导致了一个错误,在此记录下来. 正文 如上图所示,'32'%2就是错误发生的地方. 我以为我拿到的是一个int类型的32,想判断它是偶数还是奇数. 实际上我拿到的是一个str类型的'32',这时python的解释器并没有把%理解成取余,而是理解成了这种东西. 我不知道"这种东西"的定义,但知道其用法和语法,其语法是这样的: name = 'cxy' print('%s is handsom

TypeError: not all arguments converted during string formatting

print ("So, you're 5r old, %r tall and %r heavy." % (age, height, weight)) print ("So, you're %r old, %r tall and %r heavy." % (age, height, weight)) 说明前后%和后面的参数数量不对应.红色就是错误的地方.

Python TypeError: not enough arguments for format string

今天使用mysqldb执行query语句的时候,在执行这条语句的时候: select PROJ, DATE_FORMAT(MAX(DATE),'%Y-%m-%') AS MAXDATE, DATE_FORMAT(MIN(DATE),'%Y-%m-%d') AS MINDATE FROM (SELECT resource.PROJ,`day`.DATE FROM resource,`day` where resource.MAC=`day`.MAC ORDER BY PROJ) AS PROJSE

TypeError: not enough arguments for format string

Error msg: --- Logging error --- Traceback (most recent call last): File "/usr/lib/python3.6/logging/__init__.py", line 993, in emit msg = self.format(record) File "/usr/lib/python3.6/logging/__init__.py", line 839, in format return fm

Python-TypeError: not all arguments converted during string formatting

Where? 运行Python程序,报错出现在这一行 return "Unknow Object of %s" % value Why? %s 表示把 value变量装换为字符串,然而value值是Python元组,Python中元组不能直接通过%s 和 % 对其格式化,则报错 Way? 使用 format 或 format_map 代替 % 进行格式化字符串 出错代码 def use_type(value): if type(value) == int: return "i

statsmodels.tsa.arima_model预测时报错TypeError: int() argument must be a string, a bytes-like object or a number, not &#39;Timestamp&#39;

在 python 中用 statsmodels创建 ARIMA 模型进行预测时间序列: import pandas as pd import statsmodels.api as sm df = pd.read_csv("data.csv", index_col=0, parse_dates=True) mod = sm.tsa.statespace.SARIMAX(df['price'], enforce_stationarity=False, enforce_invertibili

TypeError at /admin/booktest/bookinfo/ expected string or buffer

问题描述: Request Method: GETRequest URL: http://127.0.0.1:8000/admin/booktest/bookinfo/Django Version: 1.8.2Exception Type: TypeErrorException Value: expected string or bufferException Location: /home/python/.virtualenvs/h1/local/lib/python2.7/site-pack

【python】判断年份是否为闰年

1.计算今年是闰年嘛?判断闰年条件, 满足年份模400为0, 或者模4为0但模100不为0. 代码如下: 1 x = int(raw_input('please enter a year:')) 2 if x % 4 == 0 and x % 100 != 0: 3 print 'yes' 4 elif x % 400 == 0: 5 print u"yes" 6 else: 7 print u"no" 关键点: 1.sublime text 2中需要加载subli

Python基础教程笔记——使用字符串

使用字符串 Table of Contents 1 基本字符串操作 2 字符串格式化:精简版 2.1 用字符串格式化操作符 2.2 用string的Template格式化字符串 3 字符串格式化:完整版 3.1 转换说明符 3.2 简单转换 3.3 字段宽度和精度 3.4 符号,对齐和 0 填充 4 字符串方法 4.1 find 4.2 join 4.3 lower 4.4 replace 4.5 split 4.6 strip 4.7 translate 1 基本字符串操作 说明:字符串也是序