有一种方法可以在python中输入包含破折号的字符串块[关闭]

问题描述 投票:-1回答:2

提到的代码无法接受输入

037-00901-00027
#batch printer
     batch_id=float(input("enter your product ID"))
     print("Your Country code is=", batch_id[0:3])
     print("Your product code is=", batch_id[4:9])
     print("Your Batch Number is=", batch_id[9:13])
python
2个回答
0
投票
batch_id = input("enter your product ID: ")
IDs = batch_id.split('-')
print("Your Country code is =", IDs[0])
print("Your product code is =", IDs[1])
print("Your Batch Number is =", IDs[2])

0
投票

尝试

batch_id=str(input("enter your product ID"))
splitter = batch_id.split('-')
print("Your Country code is=", splitter[0])
print("Your product code is=", splitter[1])
print("Your Batch Number is=", splitter[2])
© www.soinside.com 2019 - 2024. All rights reserved.