当前位置:网站首页>Calculate the odd sum of 1~n (1~100 as an example)
Calculate the odd sum of 1~n (1~100 as an example)
2022-07-04 03:33:00 【Yueyechong】
n=int(input())
sum=0
for i in range(1,n+1,2):
sum+=i
print(sum)Input 100 have to 2500
utilize range function :range(1,5,2) # For from 1 To 5, interval 2( It doesn't contain 5)
Method 2: use while,matlab Thought
b=int(input())
n=1
sum=0
while n<b:
sum+=n
n+=2
print(sum)Method 3
n=int(input())
sum=0
ls=[]
for i in range(1,n+1):
if i %2!=0:
sum+=i
print(sum)Method 5: If you want to check the inside
n=int(input())
sum=0
ls=[]
for i in range(1,n+1):
if i %2!=0:
sum+=i
ls.append(i)# Show list , Beginners can't debug Internal numbers can be displayed in a list
print(ls)# Show the numbers
print(sum)Is the number correct , It can be displayed in a list
边栏推荐
- Webhook triggers Jenkins for sonar detection
- 96% of the collected traffic is prevented by bubble mart of cloud hosting
- If you have just joined a new company, don't be fired because of your mistakes
- super_ Subclass object memory structure_ Inheritance tree traceability
- Site favorites
- Learning video website
- How about the ratings of 2022 Spring Festival Gala in all provinces? Map analysis helps you show clearly!
- Backpropagation formula derivation [Li Hongyi deep learning version]
- JVM family -- monitoring tools
- Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
猜你喜欢

@Scheduled scheduled tasks

Explain AI accelerator in detail: why is this the golden age of AI accelerator?

Résumé: entropie, énergie libre, symétrie et dynamique dans le cerveau

Constantly changing harmonyos custom JS components during the Spring Festival - Smart Koi

What is cloud primordial?

1day vulnerability pushback skills practice (3)

Is it really so difficult to learn redis? Today, a fan will share his personal learning materials!

In my spare time, I like to write some technical blogs and read some useless books. If you want to read more of my original articles, you can follow my personal wechat official account up technology c

MySQL data query optimization -- data structure of index

Consul of distributed service registration discovery and unified configuration management
随机推荐
what does ctrl + d do?
Examination question bank of constructor decoration direction post skills (constructor) and examination data of constructor decoration direction post skills (constructor) in 2022
[source code analysis] model parallel distributed training Megatron (5) -- pipestream flush
Backpropagation formula derivation [Li Hongyi deep learning version]
[PaddleSeg 源码阅读] PaddleSeg计算Dice
Setting methods, usage methods and common usage scenarios of environment variables in postman
Unity writes a character controller. The mouse controls the screen to shake and the mouse controls the shooting
[UE4] parse JSON string
Contest3145 - the 37th game of 2021 freshman individual training match_ D: Ranking
Stm32bug [the project references devices, files or libraries that are not installed appear in keilmdk]
Sword finger offer:55 - I. depth of binary tree
Contest3145 - the 37th game of 2021 freshman individual training match_ 1: Origami
JVM family -- monitoring tools
Basé sur... Netcore Development blog Project Starblog - (14) Implementation of theme switching function
Record a problem that soft deletion fails due to warehouse level error
Contest3145 - the 37th game of 2021 freshman individual training match_ E: Eat watermelon
Fudan released its first review paper on the construction and application of multimodal knowledge atlas, comprehensively describing the existing mmkg technology system and progress
Third party login initial version
Command Execution Vulnerability - command execution - vulnerability sites - code injection - vulnerability exploitation - joint execution - bypass (spaces, keyword filtering, variable bypass) - two ex
[Valentine's Day confession code] - Valentine's Day is approaching, and more than 10 romantic love effects are given to the one you love