如何在if语句中创建一个条件,接受变量列表并打印出可被5整除的数字?`
firstNumber = input("Write the First Number: ")
secondNumber = input("Write the Second Number: ")
thirdNumber = input("Write the the Third Number: ")
fourthNumber = input("Write the the Fourth Number: ")
list1 = [firstNumber, secondNumber, thirdNumber, fourthNumber]
def divisibleByFive():
for x in list1:
if x%5 == 0:
print(x)
divisibleByFive()
将其作为函数中的参数,并在调用时传递:
firstNumber = input("Write the First Number: ")
secondNumber = input("Write the Second Number: ")
thirdNumber = input("Write the the Third Number: ")
fourthNumber = input("Write the the Fourth Number: ")
list1 = [firstNumber, secondNumber, thirdNumber, fourthNumber]
def divisibleByFive(l1):
for x in l1:
if int(x)%5 == 0:
print(int(x))
divisibleByFive(list1)
不喜欢传球?使用全局变量,但这太过分了:-(
firstNumber = input("Write the First Number: ")
secondNumber = input("Write the Second Number: ")
thirdNumber = input("Write the the Third Number: ")
fourthNumber = input("Write the the Fourth Number: ")
list1 = [firstNumber, secondNumber, thirdNumber, fourthNumber]
def divisibleByFive():
global list1
for x in list1:
if int(x)%5 == 0:
print(int(x))
divisibleByFive()