繁体   English   中英

列表打印字母而不是字符串?

[英]List prints letters and not strings?

我很难正确打印以下内容:

core = 1, 2, 3, 4, 5
glutes = 6, 7, 8, 9, 10
upper = 11, 12, 13, 14, 15
lower = 16, 17, 18, 19, 20
conditioning = 21, 22, 23, 24, 25

core_ability = int(input("Core: "))
glute_ability = int(input("Glutes: "))
if core_ability > 4:
        upper_ability = int(input("Upper body: "))
else:
        ""
lower_ability = int(input("Lower body: "))

conditioning_ability = int(input("\nConditioning ability level:"))

newcore = core[0:core_ability]
newglutes = glutes[0:glute_ability]
if core_ability > 4:
        newupper = upper[0:upper_ability]
newlower = lower[0:lower_ability]
newconditioning = conditioning[0:conditioning_ability]

if core_ability > 4:
        movement_bank = str(newcore) + str(newglutes) + str(newupper) + str(newlower) + str(conditioning_ability)
else:
       movement_bank = str(newcore) + str(newglutes) + str(newlower) + str(conditioning_ability)

sections = int(input("\nNumber of GPP sections in the session: "))

print("\nSPECIFY THE NUMBER OF MOVEMENTS PER SECTION")

if sections == 1:
        section1_num = int(input("Section 1:"))
        print(random.sample(movement_bank[0:], k=section1_num))

我得到一个输出,看起来像:

' ', ' ', 'r'

当我想得到类似的东西时:

'1', '16', '8'

我在“movement_bank”列表中的每个列表中添加了“str()”,因为没有它我得到一个错误:TypeError: can only concatenate list (not "int") to list。

非常感谢所有帮助。

看来,您有不同的列表,并希望将它们全部合并为一个列表。 使用extend

core = 1, 2, 3, 4, 5
glutes = 6, 7, 8, 9, 10
upper = 11, 12, 13, 14, 15
lower = 16, 17, 18, 19, 20
conditioning = 21, 22, 23, 24, 25

movement_bank = []
core_ability = int(input("Core: "))
movement_bank.extend(core[:core_ability])
glute_ability = int(input("Glutes: "))
movement_bank.extend(glutes[:glute_ability])
if core_ability > 4:
    upper_ability = int(input("Upper body: "))
    movement_bank.extend(upper[:upper_ability])
lower_ability = int(input("Lower body: "))
movement_bank.extend(lower[:lower_ability])
conditioning_ability = int(input("\nConditioning ability level:"))
movement_bank.extend(conditioning[:conditioning_ability])

sections = int(input("\nNumber of GPP sections in the session: "))
print("\nSPECIFY THE NUMBER OF MOVEMENTS PER SECTION")
if sections == 1:
    section1_num = int(input("Section 1:"))
    print(random.sample(movement_bank, k=section1_num))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM