2017-02-26 676 views

回答

0

什麼是模運算符和右手分左手操作操作數並返回餘數。所以如果餘數等於0,則左操作數是右操作數的倍數。

因此

your_number%2 == 0回報True如果your_number是2

your_number%3 != 0回報倍數True如果your_number不是3

倍數爲您提供一個完整的回答,你需要的是:

if myint%2 == 0 and myintr%3 != 0: 
    print(str(myint), "is a multiple of 2 and not a multiple of 3") 
0

這是你如何做到這一點:

#first checks if myint/2 doesn't has a reminder 
#then checks if myint/3 has a reminder 
if not myint % 2 and myint % 3: 
    print(myint,"is a multiple of 2 only") 

,或者如果你想:

if myint % 2 == 0 and myint % 3 != 0: 
    print(myint,"is a multiple of 2 only") 

都工作在同一

+0

您的True/False評估風格是[*不適用於Google的Python程序](https://google.github.io/styleguide/pyguide.html?showone=True/False_evaluations#True/False_evaluations)。我的意思是你的'如果不是myint%2'。 – Kanak

+0

它沒有任何問題 – abccd