Python';s模误解

Python';s模误解,python,datetime,modulo,Python,Datetime,Modulo,我有那个代码,但我不认为我真的理解模如何返回余数,不擅长数学 代码如下: #import the datetime class import datetime #declare and initialize variables strDeadline = "" totalNbrDays = 0 nbrWeeks = 0 nbrDays = 0 #Get Today's date currentDate = datetime.date.today() #Ask the user for th

我有那个代码,但我不认为我真的理解模如何返回余数,不擅长数学

代码如下:

#import the datetime class
import datetime

#declare and initialize variables
strDeadline = ""
totalNbrDays = 0
nbrWeeks = 0
nbrDays = 0

#Get Today's date
currentDate = datetime.date.today()

#Ask the user for the date of their deadline
strDeadline = input("Please enter the date of your deadline (mm/dd/yyyy): ")

deadline = datetime.datetime.strptime(strDeadline,"%m/%d/%Y").date()

#Calculate number of days between the two dates
totalNbrDays = deadline - currentDate

#For extra credit calculate results in weeks & days

nbrWeeks = totalNbrDays.days / 7

#The modulo will return the remainder of the division
#which will tell us how many days are left 
nbrDays = totalNbrDays.days%7

#display the result to the user

print("You have %d weeks" %nbrWeeks + " and %d days " %nbrDays + "until your deadline.")

模用于取表达式的剩余部分

例如,当你做15%7时,你得到1。这是因为7+7+1=15


在代码中,取总天数(totalnbrides.days)除以一周内的天数(7)。让我们以30为例来表示总天数。30%7等于2,因为7+7+7+7+2=30,或(7*4)=28,30-28=2。

模用于取表达式的其余部分

例如,当你做15%7时,你得到1。这是因为7+7+1=15


在代码中,取总天数(totalnbrides.days)除以一周内的天数(7)。让我们以30为例来表示总天数。30%7等于2,因为7+7+7+7+2=30,或者(7*4)=28,30-28=2。

当你将一个整数除以另一个整数时,它并不总是均匀的。例如,
23/7
将为您提供剩余的
2
,因为
23=7*3+2
。模给你除法运算的余数<代码>23%7=2。当您的天数超过一周的时间时,这非常有用。您可以使用整数除法(意味着商将是一个整数)计算周数
23/7=3
,然后用模计算剩余天数
23%7=2
,告诉您23天等于3周2天。

当您将一个整数除以另一个整数时,它并不总是均匀地进入。例如,
23/7
将为您提供剩余的
2
,因为
23=7*3+2
。模给你除法运算的余数<代码>23%7=2。当您的天数超过一周的时间时,这非常有用。您可以使用整数除法(意味着商将是一个整数)计算周数
23/7=3
,然后用模计算剩余天数
23%7=2
,告诉您23天等于3周2天。

您的问题是什么,代码的预期结果是什么,实际结果是什么?您的问题是什么,代码的预期结果是什么,实际结果是什么?