第4章-20 求矩阵各行元素之和

遇到一个麻烦的事情:

上面a,b输入,如果一起输入转int会报错,因为int只能一对一

但是明明我分开来int了,下面第十行还是报错说我的b是string字符,难不成b还把空格吃进去了?

参考一种聪明的算法:

length, width = input().split()
length = int(length)
width = int(width)
sum1 = 0
index = 1
l = []
while 1:
a = input().split()
d = map(int, a)
d = sum(d)
l.append(d) if index >= length:
break
index += 1
for i in l:
print(i)

一行一行算

PTA的Python练习题(十八)的更多相关文章

  1. PTA的Python练习题(八)

    从 第3章-15 统计一行文本的单词个数 继续 1. s = input() count=0 for c in s: if c==' ': count=count+1 if c=='.': break ...

  2. PTA的Python练习题(十五)

    第4章-12 求满足条件的斐波那契数 a=eval(input()) b=c=1 d=1 for i in range(a): c=b b=d d=b+c if d>a: print('{}'. ...

  3. PTA的Python练习题(十六)

    第4章-15 换硬币 挺难的,这里学到一个range的用法: 也就是说range函数能实现顺序和倒序,取决于step是正是负 count = 0 x = int(input()) a = x // 5 ...

  4. PTA的Python练习题(十四)

    第4章-10 最大公约数和最小公倍数 m,n=map(int,input().split()) min=0 a=b=0 if m >n: min=m else: min=n for i in r ...

  5. PTA的Python练习题(十二)-第4章-7 统计学生平均成绩与及格人数

    第4章-7 统计学生平均成绩与及格人数 a=eval(input()) b=list(map(int,input().split())) sum=sum(b) c=[i for i in b if i ...

  6. PTA的Python练习题(十二)-第4章-6 输出前 n 个Fibonacci数

    接下来应该做到 第4章-6 输出前 n 个Fibonacci数 了 def fib(n): a,b = 0,1 for i in range(n+1): a,b = b,a+b return a n= ...

  7. PTA的Python练习题(十)

    从 第3章-22 输出大写英文字母 开始 1. a=str(input()) b='' for i in a: if 'A'<=i<='Z' and i not in b: b=b+i i ...

  8. PTA的Python练习题(三)

    继续在PTA上编写Python的编程题. 从 第2章-11 求平方与倒数序列的部分和 开始 1. a,b=map(int,input().split()) s=0 while(a<=b): s= ...

  9. PTA的Python练习题(二)

    继续在PTA上练习Python (从 第2章-5 求奇数分之一序列前N项和  开始) 1. x=int(input()) a=i=1 s=0 while(i<=x): s=s+1/a a=a+2 ...

随机推荐

  1. V8 是怎么跑起来的 —— V8 中的对象表示

    V8 是怎么跑起来的 —— V8 中的对象表示 ThornWu The best is yet to come 30 人赞同了该文章 本文创作于 2019-04-30,2019-12-20 迁移至此本 ...

  2. mysql数据库测试脚本

    背景: 对mysql的底层代码进行了重构,需要回归测试mysql的基本功能 测试目标: 涵盖功能点如下 1.创建库,删除库,重命名库 2.创建表(需要涵盖所有基本的数据类型,主键,自增,默认值,不允许 ...

  3. Suggestions On Setting LED Holiday Light

    We all like the cheerful glow of holiday lights, so the process goes seamless from start to finish. ...

  4. [LOJ144] DFS 序 1 - DFS序 线段树

    为熟悉机房键盘而划水 #include <bits/stdc++.h> using namespace std; #define int long long const int N = 4 ...

  5. unity命令行参数

    Typically, Unity will be launched by double-clicking its icon from the desktop but it is also possib ...

  6. CSS布局的四种定位方式

    1.static(静态定位): 默认值.没有定位,元素出现在正常的流中(忽略 top, bottom, left, right 或者 z-index 声明).参考上篇随笔. 2.relative(相对 ...

  7. OmniGraffle原型案例 | 某APP产品原型PDF文件分享之二

    1.从 App 首页进入商城 App底部 Tab有社区.商城,我们点击「商城」进入「乐宠商城」,下面简称商城.商城采用的是经典的宫格式导航设计(还有普通列表式.和瀑布流列表式.或两者皆有等),主要有搜 ...

  8. python3爬取百度知道的问答并存入数据库(MySQL)

    一.链接分析: 以"Linux"为搜索的关键字为例: 首页的链接为:https://zhidao.baidu.com/search?lm=0&rn=10&pn=0& ...

  9. mini-batch是什么 以及dataloader的作用

    mini-batch是什么 以及dataloader的作用 待办 我们在训练神经网络时,使用的是mini-batch(一次输入多张图片),所以我们在使用一个叫DataLoader的工具为我们将5000 ...

  10. Django_Setings

    """ Django settings for untitled1 project. Generated by 'django-admin startproject' u ...