在python中,为什么程序不允许我从美国导入数据

2024-09-26 17:51:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着从用户那里获取数据,然后打印这个月的日历为什么我的代码没有导出任何东西 注意我必须保留或使用def printCalender()

import calendar

def printCalender():
    month=int(input("please enter month date and year hit enter after each digit is placed: "))
    day=int(input())
    year=int(input())
    print(calendar.sunday(month,day,year)) 

Tags: and代码用户importinputdatedefyear
3条回答

试试这个。你所需要的只是年和月。不需要日期

def printCalender():
    month=int(input("please enter month and year hit enter after each digit is placed: "))
    year=int(input())
    print(calendar.month(year,month))


printCalender()

输出

please enter month and year hit enter after each digit is placed: 6
2012
     June 2012
Mo Tu We Th Fr Sa Su
             1  2  3
 4  5  6  7  8  9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30

如果你看你的输入语句-你用错误的方式来表达它们:

你可以month = input(int())

你应该在哪里做month = int(input())

根据评论-->; 完成后,确保调用printCalender()

一旦您做了这些更改,您的代码就应该可以工作了。你知道吗

据我所知,你实际上并没有运行这个函数。试试这个:

import calendar

def printCalender():
    month=int(input("please enter month date and year hit enter after each digit is placed: "))
    day=int(input())
    year=int(input())
    print(calendar.sunday(month,day,year))

printCalender() 

相关问题 更多 >

    热门问题