python-3.x - 星期几程序 Python3

标签 python-3.x dayofweek

它告诉我在第 19 行周围的报价单上有一个无效语法: year = int(input("请输入年份:")) while(年份 < 1900 或年份 > 2100): 打印“错误超出范围,请重新输入”

我真的不知道那是什么。它说它在引号周围,但缩进看起来很好,还有括号。我在那里尝试了一切,但我不知道

我的程序:

def isLeapYear(year):

    if year % 400 == 0:
        return True
    elif year % 100 == 0:
        return False
    elif year % 4 ==0:
        return True
    else:
        return False

def conversion(month):
    conversionmonth = (month + 10) % 12
    return conversionmonth

def main():

    year = int(input("Enter year: "))
     while (year < 1900 or year > 2100):
     print"Error out of range. Please re-input"
     year = int(input("Enter year: "))
    if isLeapYear(year):
     print "is a leap year"
    else:
     print "is not a leap year"


    month = int(input("Enter month: "))
    month = conversion(month)
     while (month < 1 or month > 12)
      print "Error out of range. Please re-input"
       month = int(input("Enter month: ")

    day = int(input("Enter day: "))
     while (day < 1 or input > 31)
      if month == February and day > 29:
       print "Error out of range. Please re-input"
        day = int(input("Enter day: ")
        if isLeapYear and day > 28:
         print "Error out of range. Please re-input"
          day = int(input("Enter day: ")
     print "Error out of range. Please re-input"
      day = int(input("Enter day: ")

    a = month
    b = day
    c = year
    d = year // 100
    w = (13 * a - 1) // 5
    x = c // 4
    y = d // 4
    z = w + x + y + b + c - 2 * d
    r = z % 7
    r = (r + 7) % 7
     if (r == 0):
      print "Sunday"
     if (r == 1):
      print "Monday"
     if (r == 2):
      print "Tuesday"
     if (r == 3):
      print "Wednesday"
     if (r == 4):
      print "Thursday"
     if (r == 5):
      print "Friday"
     if (r == 6):
      print "Saturday"

main()

最佳答案

在 Python 3 中,print 是一个函数,您必须用类似的方式调用它

print("Error out of range. Please re-input")

关于python-3.x - 星期几程序 Python3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17460787/

相关文章:

Python从xml中提取数据

python - 如果从函数内部执行,带有 "apply_async"的多处理池不会执行任何操作

python - postgres 和 postgresql_psycopg2 作为 django 的数据库引擎有什么区别?

python - 在 Django Rest 中传递 URL 中的日期范围

python - 如何检查字符串是否只包含 UTF-8 字符

c++ - 我想在此代码中添加工作日

java - 使用 with* 函数、TemporalAdjusters 或设置 TemporalFields 调整 ZonedDateTimes 之间有什么区别吗?

javascript - 在javascript中显示明天的名字?

python - 获取 DataFrame 的 Datetime 列的工作日/星期几

javascript - Momentjs 一周的第一天