我无法让最后一行在我的显示屏上展开

问题描述 投票:0回答:1

我有以下代码来从输入打印时间表,但无法使最后一行像标题一样展开。

我的showRecord代码如下...

Class Appointment:
    def __str__(appt):
        return f'{appt.date} {appt.start} {appt.end} {appt.description} {appt.venue} {appt.priority}'

其他代码直到

def showRecords(schedule):
    print('{:<15}{:<10}{:<8}{:<25}{:<25}{:<10}'.format("Date","Start","End","Subject","Venue","Priority")) # '<' here aligns text to left
    print('{:<15}{:<10}{:<8}{:<25}{:<25}{:<10}'.format("----","-----","---","-------","-----","--------"))
    for appointment in schedule:
        print(appointment)
    else:
        print("No more appointments found.")

我尝试过以下方法

print('{:<15}{:<10}{:<8}{:<25}{:<25}{:<10}'.format(schedule))

...还有...

print('{:<15}{:<10}{:<8}{:<13}{:<11}{:<10}'.format(date, start, end, description, venue, priority))

但最后一行只是聚集在一起,如下......

我已经尝试了上面提到的几种代码,但无法使其工作。请帮忙。

注意:我已经添加了其余的代码!

python scheduler display show
1个回答
0
投票
def showRecords(schedule):
    print('{:<15}{:<10}{:<8}{:<25}{:<25}{:<10}'.format("Date","Start","End","Subject","Venue","Priority")) # '<' here aligns text to left
    print('{:<15}{:<10}{:<8}{:<25}{:<25}{:<10}'.format("----","-----","---","-------","-----","--------"))
    for appt in schedule:
        print(f'{appt.date:<15}{appt.start:<10}{appt.end:<8}{appt.description:<25}{appt.venue:<25}{appt.priority:<10}')
    else:
        print("No more appointments found.")
© www.soinside.com 2019 - 2024. All rights reserved.