簡體   English   中英

為什么我得到這個 ValueError

[英]Why am i getting this ValueError

現在這是來源。 有人請幫我處理這個問題

for k in range(no_of_resc):
                name_resch = input('enter then name of the patient you want to reschedule : ')
                date_resc = input('enter the date you want to reschedule : ')
                date_for_resc = datetime.datetime.strptime(date_resc, '%Y-%m-%d %H:%M:%s')
                print('the appointment is rescheduled for ',name_resch,'and on',date_for_resc)
                resch_pat.append(name_resch)
            print('the appointment is rescheduled for :' , resch_pat)

現在現在這是 output 所以這里我有 6 個選項(忘記那些選項)當我輸入我想要預約的日期時我收到類似 ValueError 的錯誤

1 . register no.of  doctors 
2 . register no.of patients 
3 . do you want to book appointments ? 
4 . reschedule the appointments ?      
5 . cancel the appointments. 
6 . Exit 
enter your selection : 3 
enter the number of doc : 1 
enter number of patient : 1 
>> 
enter the name of the doctor : knan 
is the doctor free? (y/n) : y 
[]
['y ']
enter the name of the patient : ganesh 
['ganesh ']
lol
enter the date you want to get appointed (yyyy-mm-dd hh:mm): 2023-10-9 8:31:31 
Traceback (most recent call last):
  File "c:\Desktop\vsc\JavaScript\05-Guess-My-Number\starter\doctor.py", line 51, in <module>
    date = datetime.datetime.strptime(appnt_date,'%Y-%m-%d %H:%M')
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\_strptime.py", line 568, in _strptime_datetime        
    tt, fraction, gmtoff_fraction = _strptime(data_string, format)
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python311\Lib\_strptime.py", line 352, in _strptime
    raise ValueError("unconverted data remains: %s" %
ValueError: unconverted data remains: :31 

在此行中,您輸入帶秒數的日期:

enter the date you want to get appointed (yyyy-mm-dd hh:mm): 2023-10-9 8:31:31

但是這種模式的轉換不正確,你在這里 (c:\Desktop\vsc\JavaScript\05-Guess-My-Number\starter\doctor.py):

date = datetime.datetime.strptime(appnt_date,'%Y-%m-%d %H:%M')

轉換應該是:

date = datetime.datetime.strptime(appnt_date,'%Y-%m-%d %H:%M:%s')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM