创建一个python程序,用户在其中输入一个月,它会告诉您y的下一个月

2024-06-25 22:43:24 发布

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

我想创建一个python程序,你可以输入一个月,它会告诉你下个月

到目前为止,我终于想出了这个办法——只要我在运行代码时输入'march'就不会有语法错误,例如,它会给我一长串print语句

print('Hello and welcome to the program, enter a month of the year and the program will tell you the following month')
month = input('Please enter a month:')
if month == 'January' or 'january':
    print ('The next month will be February')

if month == 'February' or 'february':
        print ('The next month will be March')

if month == 'March' or 'march':
            print ('The next month will be April')

if month == 'April' or 'april':
            print ('The next month will be May')

if month == 'June' or 'june':
            print ('The next month will be July')

if month == 'July' or 'july':
            print ('The next month will be August')

if month == 'August' or 'august':
            print ('The next month will be September')

if month == 'September' or 'september':
            print ('The next month will be October')

if month == 'October' or 'october':
            print ('The next month will be November')

if month == 'November' or 'november':
            print ('The next month will be December')

if month == 'December' or 'december':
            print ('The next month will be January')

Tags: orandtheifbeprogramwillnext
1条回答
网友
1楼 · 发布于 2024-06-25 22:43:24

好的语法是:

if month == 'December' or month == 'december': 

否则python将'december'转换为布尔值,结果将是True(对于任何非空字符串)

相关问题 更多 >