Python 我已经包括了我遇到的错误的图像
编写一个Python程序,针对给定的数字显示如下消息: 如果是三的倍数,则显示“Zip”;如果是五的倍数,则显示“Zap”。如果是3和5的倍数,则显示“缩放”。如果不满足上述任何给定条件,则显示“无效”。 #PF-Exer-11Python 我已经包括了我遇到的错误的图像,python,python-3.x,python-2.7,Python,Python 3.x,Python 2.7,编写一个Python程序,针对给定的数字显示如下消息: 如果是三的倍数,则显示“Zip”;如果是五的倍数,则显示“Zap”。如果是3和5的倍数,则显示“缩放”。如果不满足上述任何给定条件,则显示“无效”。 #PF-Exer-11 def display(num): message="" #write your logic here if(num%3==0): print("zip") elif(num%5==0): print("z
def display(num):
message=""
#write your logic here
if(num%3==0):
print("zip")
elif(num%5==0):
print("zap")
elif(num%3==0 and num%5==0):
print("zoom")
else:
print("Invalid")
return message
[enter image description here][1]
#Provide different values for num and test your program
message=display(9)
print(message)[enter image description here][1]
你并没有具体说明你的问题是什么,但我猜测输入15次打印
zip
,而不是zoom
首先将支票移动为3和5的倍数
def显示(num):
message=“”
#把你的逻辑写在这里
如果(num%3==0和num%5==0):#这是我能想到的最简单的解决方案:)
欢迎来到堆栈溢出!请在您发布问题时,确保明确说明您遇到的问题以及如何重现问题,以便帮助者更容易回答
def display(num):
#write your logic here
if(num%3==0 and num%5==0):
return "Zoom"
elif(num%5==0):
return "Zap"
elif(num%3==0):
return "Zip"
else:
return "Invalid"
print(display(15))