简体   繁体   中英

How do I solve the issue “can't multiply sequence by non-int of type 'float'” in python

string = (input("Input a string of random chars! "))
multi = int(len(string))
multi1 = float(multi)
print(multi)
print(("-") * round((multi * 10),1))
print("|", ("_") * round((multi1/2),1), "|")

您需要int来重复字符串

print("|", ("_") * int(round((multi1/2),1)), "|")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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