日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python奇偶求和_python 判断奇偶并求和,运行过程有错误,希望高手给指导一下。...

發布時間:2023/12/3 python 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python奇偶求和_python 判断奇偶并求和,运行过程有错误,希望高手给指导一下。... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

問題是:b) Add to the condition in the while loop so that it will stop if either the user inputs a zero or the sum is larger than limit (if limit is None then ignore the second stopping condition). Do not use a break statement to implement this feature.

底下是我寫的程序,可是運行過程并沒有按照描述運行,有錯誤:

def sum_odd_inputs(limit = None):

"""(integer) -> integer

Asks the user to enter a set of integer inputs. The function sums all odd

inputs (it discards all even inputs). The user can indicate that the set is

complete by entering the integer 0. The set will also be considered complete

if the running sum exceeds limit. If limit == None, then only a user input

of zero will complete the set.

>>>sum_odd_inputs()

Enter an integer (0 to quit): 5

Enter an integer (0 to quit): 6

Enter an integer (0 to quit): 10

Enter an integer (0 to quit): 7

Enter an integer (0 to quit): 0

12

>>>sum_odd_inputs(10)

Enter an integer (0 to quit):2

Enter an integer (0 to quit):3

Enter an integer (0 to quit):5

Enter an integer (0 to quit):1

Enter an integer (0 to quit):3

12

"""

set_sum = 0

user_input = raw_input ('Enter an integer (0 to quit):')

def even_number():

user_input%2 == 0

def odd_number():

user_input%2 != 0

while user_input%2 != 0:

if user_input != 0:

set_sum += user_input

elif set_sum <= 10:

set_sum += user_input

return set_sum

總結

以上是生活随笔為你收集整理的python奇偶求和_python 判断奇偶并求和,运行过程有错误,希望高手给指导一下。...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。