Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
伪代码-zellers同余-python_Python_Date_Pseudocode - Fatal编程技术网

伪代码-zellers同余-python

伪代码-zellers同余-python,python,date,pseudocode,Python,Date,Pseudocode,我正在上编程(python)的第一堂课。我的任务是编写伪代码和稍后的python程序,该程序将使用dd/mm/yyyy作为输入来计算一周中的哪一天。我用它来计算一周中的哪一天。这是我作为伪代码的第一次尝试——我希望得到一些反馈。我不确定我是否在正确的轨道上。我的逻辑清楚吗?初学者能够将其翻译成python吗?任何提示或帮助都将不胜感激 Program Calculate the Day Purpose of the program: this program inputs a date and

我正在上编程(python)的第一堂课。我的任务是编写伪代码和稍后的python程序,该程序将使用dd/mm/yyyy作为输入来计算一周中的哪一天。我用它来计算一周中的哪一天。这是我作为伪代码的第一次尝试——我希望得到一些反馈。我不确定我是否在正确的轨道上。我的逻辑清楚吗?初学者能够将其翻译成python吗?任何提示或帮助都将不胜感激

Program Calculate the Day
Purpose of the program: this program inputs a date and calculates the day of the week on which it occurred.
Date: 6/4/14

# Prompt a user to type his/her birthdate as three different values

print "In what month were you born?"
Input mm

print "on what day of the month?"
Input dd

print "In what year were you born?"
Input yyyy

# adjusts inputs to account for algorithm if birthdate occurs on Jan or Feb

if input mm = 1 or mm = 2:

mm = mm + 12 

and

yyyy = yyyy - 1

# stores inputs as variables for use in zellers congruence

store mm as m
store dd as q
store yyyy as y

# Calculate the day of the week and store it in a variable named dow

dow = ( ( q + ( (m + 1) * 26 // 10 )+ Y +( Y // 4 )+ 6 * (Y // 100 )+ (Y // 400 )) % 7 )

Output "you were born on a Day" dow

# Notice that there is no space between the word “Day” and the number; this helps it look like one of those “number for days” cultures

我最近开始学习python,并为您的问题找到了解决方案。如果您喜欢或有任何问题,请告诉我

#importing functions
import time 
import sys
import datetime
import math 
start=time.perf_counter()#starting timer
hi=str(input('enter date in mm/dd/yyyy'))#asking for input
try:
    date= datetime.datetime.strptime(hi,'%m/%d/%Y').date()#checking for format
    d2=str(date.year)
    l3=d2[:2] #breaking up string 
    l4=d2[2:]
    C=int(l3)
    D=int(l4)
    K=date.day
    M=date.month
if M==1:# making zellers month system 
    D=D-1
    M=11
elif M==2:
    D=D-1
    M=12
else:
    M=M-2
#breaking up the equation.The equation is  f = k + [(13*m-1)/5] + D + [D/4] + 
[C/4] - 2*C
f=13*M
g=f-1
a=g/5
a=math.floor(a) #cutting off the decimals
z=a+K
b=D/4
b=math.floor(b)
c=C/4
c=math.floor(c)
d=2*C
f1=(z+b+c+D)
d1=f1-d   
l=d1 % 7 # getting remainder
l=math.floor(l)#cutting off decimals 
if (l==1):#using remainder to find day of week
    print('The day is Mon')
elif (l==2):
    print('The day is Tue')
elif (l==3):
    print('The day is Wed')
elif (l==4):
    print('The day is Thu')
elif (l==5):
    print('The day is Fri')
elif (l==6):
    print('The day is Sat')
elif (l==7 or 0):
    print('The day is Sun')
#printing the day

except Exception:
        print('Please enter date in correct format')#error statement 
else:
    #calculating final time
    end=time.perf_counter()
    a5=end-start
    message='The time taken is %s seconds'
    print(message % a5)#displaying time

看起来不错。你的问题到底是什么?如果用户输入了有效的数据,那么如果你正确地转录了Zeller的同余,它或多或少会起作用-我没有检查过。您的输出应该反映输入和答案,这样您就可以知道计算机认为您输入了什么。您可能需要考虑用户输入一个月数,如0、-1、13等;您可能应该考虑将它们输入天,例如-1、0、32(当月份为11、4、6或9时为31;当月份为2时为29或30)。也许你们也应该限制几年的时间。非常感谢你们!我也很担心。。。什么是限制伪代码输入范围的好方法?我是一个完全的初学者-我还担心我修改mm和yyyy输入的部分。甚至可以在python中修改它们并将它们存储为m和y变量吗?