我是Python的新手,我们目前正在学习如何使用if / elif / else以及作为教授的练习。希望我们编写一个可以回答年份是否为a年的程序。我找到了一个指南,向您展示了如何编写这样一个程序的很好的解释。
代码看起来像这样:
year = int(input("Please Enter the Year Number you wish: "))
if (year%400 == 0):
print("%d is a Leap Year" %year)
elif (year%100 == 0):
print("%d is Not the Leap Year" %year)
elif (year%4 == 0):
print("%d is a Leap Year" %year)
else:
print("%d is Not the Leap Year" %year
我试图弄清楚但仍找不到很好的答案的唯一原因是作者为什么使用print("%d this is a leap year" %year)
为什么运行程序时在字符串中没有显示%d
时会出现%d
?
%d表示您希望在string之后有一个integer int32,在您的情况下,这是每个打印语句后的一年