[英]Python: How can I read in the characters from a line in a file and convert them to floats and strs, depending on if they are numbers or letters?
[英]Can I convert numbers to amount of characters in Python
我可以将像 3 这样的数字转换成一个字符串,让我知道输入中的字符数量吗? 比如:3 = --- 和 6 = ------
当然:
def print_dash(n):
print("-" * n)
Output:
print_dash(5)
-----
尝试这个:
n=3
print(n*"-")
# ---
n=6
print(n*"-")
# ------
Python 对这类问题有一个简单的格式:
print("-" * n)
n = int(input("Enter your number: "))
print("-" * n)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.