在练习格式化输出时出现错误TypeError: can't multiply sequence by non-int of type 'float'

为什么会出现TypeError:不能将序列乘以’float’类型的非整数?

实际情况是,这里隐藏着一个优先级的问题

我们发现一般情况下我们在格式化输出的%后面给只一个值时没有任何问题

但一旦%后面给的是一个数学运算式时,就要注意了!!!(字符串*float是无法输出的)

 '%.2f' % 2会作为一个格式化字符串先输出,然后再会*2——所以才出现上图的2.002.00这样重复的结果,但是如果给个*0.3就没有意义了

解决方法:(改正输出优先级)

												

报错处理TypeError: can't multiply sequence by non-int of type 'float'的更多相关文章

  1. vue项目使用echarts按需引入实现地图动态显示效果时,报错:TypeError: Cannot read property 'dataToPoint' of undefined

    vue项目使用echarts按需引入实现地图动态显示效果时,报错:TypeError: Cannot read property 'dataToPoint' of undefined 借鉴了该大神的文 ...

  2. jquery3.1.1报错Uncaught TypeError: a.indexOf is not a function

    jquery3.1.1报错Uncaught TypeError: a.indexOf is not a function 使用1.9就没有问题,解决办法: 就是把写的代码中: $(window).lo ...

  3. python中读取json文件报错,TypeError:the Json object must be str, bytes or bytearray,not ‘TextIOWrapper’

    利用python中的json读取json文件时,因为错误使用了相应的方法导致报错:TypeError:the Json object must be str, bytes or bytearray,n ...

  4. 导入json文件报错,TypeError expected string or buffer

    导入json文件报错,TypeError expected string or buffer 原因:用字符串赋值后,python会把双引号转换为单引号 import json data = [{&qu ...

  5. input()报错:TypeError: '>=' not supported between instances of 'str' and 'int'

    今天学习python基础—分支与循环,接触到了if.在练习一个if语句的时候,出现了错误. 题目是: 根据分数划分成四个级别:优秀.良好.及格.不及格,分数是72: grade = 72if grad ...

  6. Appium 1.9.1 启动报错 Fatal TypeError: Class constructor BaseDriver cannot be invoked without 'new'

    安装了appium 1.9.1后一直报错Fatal TypeError: Class constructor BaseDriver cannot be invoked without 'new',无法 ...

  7. jQuery3.0+报错Uncaught TypeError: e.indexOf is not a function

    jQuery3.0+报错Uncaught TypeError: e.indexOf is not a function 使用.load()绑定事件时报错,Uncaught TypeError: e.i ...

  8. for遍历用例数据时,报错:TypeError: list indices must be integers, not dict,'int' object is not iterable解决方法

    一:报错:TypeError: list indices must be integers, not dict for i in range(0,len(test_data)): suite.addT ...

  9. faster rcnn报错:TypeError: slice indices must be integers or None or have an __index__ method

    https://blog.csdn.net/qq_27637315/article/details/78849756 https://blog.csdn.net/qq_21089969/article ...

  10. 2023-03-01 react-native 实现 复制功能 @react-native-community/clipboard 报错:TypeError: null is not an object (evaluating 'NativeClipboard_1.default.setString')。

    我的react-native(下称rn)版本为0.68,要实现这个功能主要用到rn的clipboard,在21年的时候他就已经提示clipboard会在未来的版本中上去掉,官方的建议是不要再从reac ...

随机推荐

  1. C语言:应用程序增加库函数rand的步骤

    rand函数用来生成随机数,函数原型为int rand( void ); 返回值为生成的随机数,范围0~32767.在调用rand之前可以用srand函数初始化随机数发生器来生成更随机的数. 可以通过 ...

  2. VMware安装CentOS7及远程登录详细教程

    写在前面 主要使用软件: VMware Workstation Pro17 Navicat Premium17 Xshell7 Xftp7 1.在虚拟机安装CentOS7 访问阿里云镜像站 ,选择标记 ...

  3. 前端微服务qiankun 2.x主子应用通信代码片段

    主应用代码 主应用工程里面源代码新建qiankun/index.js,通信代码如下: import { initGlobalState } from "qiankun"; impo ...

  4. OData – 坑

    前言 OData 有很多很多的坑,我的主张是能少用一样是一样,比如 Batch Processing 不要用,Inheritance 不要用,除了 GET 其它 PUT POST DELETE 都不要 ...

  5. RxJS 系列 – Error Handling Operators

    前言 前几篇介绍过了 Creation Operators Filter Operators Join Creation Operators 这篇继续介绍 Error Handling Operato ...

  6. Yarn 3.0 Plug'n'Play (PnP) 安装和迁移

    前言 以前用 npm, 后来 yarn 火了就用 yarn. 后来 yarn 2.0 大改版, Angular 不支持就一直没用. 一直到去年的 Angular 13 才开始支持. 最近又开始写 An ...

  7. react-pdf预览在线PDF的使用

    1.在react项目中安装react-pdf依赖包 建议安装8.0.2版本的react-pdf,如果安装更高版本的可能出现一些浏览器的兼容性问题: npm install react-pdf@8.0. ...

  8. Vue 文件流预览 PDF

    Vue js // pdf 预览 export function download(id) { return request({ url: '/bbs/regtech/law/download?id= ...

  9. 使用iis设置网站php版本为7.3

    内容:使用iis设置网站php版本为7.3这张图 是多少人的噩梦  早期的宝塔版本 没办法在线升级, php版本只能到7.1   默认就没有7.2以上版本   怎么办?可以在iis设置第一步: 第二步 ...

  10. C#中测试普通方法和对象类型以及泛型所需要的时间

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...