这是你的作业,所以我不会给你任何代码! 1)声明一个变量来保存总和,将其设置为零。 2)在你的循环中,检查数字是奇数还是偶数。 2.1)如果是奇数,不再做任何事情。 2.2)如果是偶数,将它加到总和上。 3)递增第一个数字,然后循环直到你的数字用完为止。 4)循环之后,打印总和。 你已经知道了如何做所有这些事情,这对你来说不应该是一个复杂的过程! Hi there! :)I'm trying to get the code to Output the sum of all the even numbers between first number and second number inclusive. I have to use the while loop!I cant get it working if any has any suggestions I would really appreciate it!What I have tried:print("Welcome")FirstNum=int(input("Enter your first number:"))SecondNum=int(input("Enter your second number:"))if (FirstNum > SecondNum): { print("First Number must be less than second number.") }while{ (FirstNum < SecondNum): for i in range(FirstNum, SecondNum, 1): while(i % 2!=0): print (i, "is odd")} 解决方案 Well...you could try answering the question, instead of recycling your last piece of homework?This is your homework, so I'll give you no code!1) Declare a variable to hold the sum, set it to zero.2) Inside your loop, check if the number is odd or even.2.1) If odd, do nothing more with it.2.2) If even, add it to the sum.3) Increment the first number, and loop round until you run out of numbers.4) After the loop, print the sum.You already know how to do all of those things so this shouldn't be a complex process for you! 这篇关于Python:打印第一个数字和第二个数字之间所有偶数的总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-13 16:19