【发布时间】:2020-01-08 19:49:49
【问题描述】:
consonant_letters = ['B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'X', 'Z']
for x in range(9999):
for y in range(consonant_letters):
for z in range(consonant_letters):
for a in range(consonant_letters):
print(f'{x} {y} {z} {a}')
*我得到的是这个
TypeError: 'list' 对象不能被解释为整数
*我正在尝试打印西班牙车牌系统中的所有数字,将其转换为列表,最后,执行输入功能,用户输入某个车牌,程序会告诉他有多少车牌直到这个车牌系统结束。
*编辑:我现在发现我唯一剩下但不知道的是如何制定输入函数。这是解决方案:
consonant_letters = ['B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M',
'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'X', 'Z']
for x in range(10000):
break
if x < 1000 and x > 99:
x = f"0{x}"
elif x < 100 and x > 9:
x = f"00{x}"
elif x < 10:
x = f"000{x}"
for y in consonant_letters:
for z in consonant_letters:
for a in consonant_letters:
print(f'{x} {y} {z} {a}')
*我尝试引入输入功能,以便用户可以输入某个车牌号,我会检测它是否存在但有问题。 这是我尝试过的:
`consonant_letters = ['B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'L',
'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'X', 'Z']
for x in range(10000):
if x < 1000 and x > 99:
x = f"0{x}"
elif x < 100 and x > 9:
x = f"00{x}"
elif x < 10:
x = f"000{x}"
for y in consonant_letters:
for z in consonant_letters:
for a in consonant_letters:
list_1 = f'{x} {y}{z}{a}'
license_plate_user = input("Write the license plate: ")
print(license_plate_user in list_1)`
*当我介绍不是 0000 BBB(第一个)的任何其他车牌时,它显示为 False。我知道这意味着循环只会执行一次,但我不知道如何修复它。
*编辑;我想出了如何执行循环,然后制定输入,但我还有一个问题。有没有我可以在知道特定车牌的情况下编写的操作来知道还剩下多少?
consonant_letters = ['B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M',
'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'X', 'Z']
for x in range(10000):
if x < 1000 and x > 99:
x = f"0{x}"
elif x < 100 and x > 9:
x = f"00{x}"
elif x < 10:
x = f"000{x}"
for y in consonant_letters:
for z in consonant_letters:
for a in consonant_letters:
list1 = f'{x} {y}{z}{a}'
if "9999 ZZZ" in list1:
license_plate_user = input("Write the license plate: ")
license_plate_user in list1
if license_plate_user:
print("Operation I do not know yet")
else:
print("Wrong values")
*编辑:我找到了一种方法,但它不起作用,我不知道为什么:
consonant_letters = ['B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M',
'N', 'P', 'R', 'S', 'T', 'V', 'X', 'Z']
total_number_of_license_plates = 80000000
for x in range(10000):
if x < 1000 and x > 99:
x = f"0{x}"
elif x < 100 and x > 9:
x = f"00{x}"
elif x < 10:
x = f"000{x}"
for y in consonant_letters:
for z in consonant_letters:
for a in consonant_letters:
list1 = f'{x} {y}{z}{a}'
if "9999 ZZZ" in list1:
license_plate_user = input("Write the license
plate: ")
license_plate_user in list1
if license_plate_user:
print(list1.index(license_plate_user))
license_plates_left =
total_number_of_license_plates - list1.index(license_plate_user)
print(f'There are {license_plates_left} license
plates left')
else:
print("Wrong values")
我得到的是:
ValueError: 未找到子字符串
【问题讨论】:
-
你的意思可能是
for y in consonant_letters:。 -
只是不要使用范围,按原样使用列表
标签: python python-3.x list python-requests