当前位置:网站首页>Chapter 2-14 sum integer segments
Chapter 2-14 sum integer segments
2022-07-28 08:44:00 【ZJUdebug3790】
Given two integers A and B, Output from A To B All the integers of and the sum of these numbers .
Input format :
Enter... On one line 2 It's an integer A and B, among −100≤A≤B≤100, Separated by spaces .
Output format :
First, output sequentially from A To B All integers of , Every time 5 A line of numbers , Each number accounts for 5 Character width , Align right . Finally, in a line, press Sum = X Output the sum of all the numbers X.
sample input :
-3 8
sample output :
-3 -2 -1 0 1
2 3 4 5 6
7 8
Sum = 30
The correct code is as follows :
a,b=map(int,input().split())
s=0
t=1
for i in range(a,b+1):
s+=i
if t%5==0:
print('{0:>5d}'.format(i))
t=1
else:
print('{0:>5d}'.format(i),end='')
t+=1
if t%5==1:
print('Sum = %d' % (s))
else:
print('\nSum = %d'%(s))At first , I first 2 Test points failed , After careful comparison, it was found that it was because of printing Sum I forgot to judge the condition
For example, the format is wrong :

边栏推荐
猜你喜欢
随机推荐
[pyqt] pyqt development experience_ How to find events and methods of controls
Flink Window&Time 原理
机器学习如何做到疫情可视化——疫情数据分析与预测实战
招贤纳士,GBASE高端人才招募进行中
Sparksql and flinksql create and link table records
SQL注入 ----前置基础
Leetcode/ sum of two numbers in a sorted array
Use of tkmapper - super detailed
How can MySQL query judge whether multiple field values exist at the same time
Let me teach you how to assemble a registration center?
GBASE亮相联通云巡展(四川站) 以专业赋能云生态
解决:IndexError: index 13 is out of bounds for dimension 0 with size 13
JS手写函数之slice函数(彻底弄懂包头不包尾)
Feign call
Creation of status bar (29)
classLoader加载的class的回收
Win the bid! Nantah general gbase 8s won the bid for the 2022 database framework project of NARI Group
Smartbi of smart smart smart software completed the c-round financing and accelerated the domestic Bi into the intelligent era
看完这12个面试问题,新媒体运营岗位就是你的了
The five pictures tell you: why is there such a big gap between people in the workplace?









