Write a program that inputs a string from the keyboard and determines the length of the string. Print the string using twice the length as the field width
时间: 2024-02-28 07:56:35 浏览: 143
TCA6416A扩展芯片
Sure, here's an example program in Python:
```python
string = input("Enter a string: ")
length = len(string)
print(f"{string:{length*2}}")
```
This program first prompts the user to enter a string using the `input()` function, and then calculates the length of the string using the `len()` function and stores it in the `length` variable.
Finally, it uses an f-string to print the string with a field width of twice the length of the string, which is achieved by multiplying the length by 2 and passing it as the field width in the f-string. The `:` character is used to specify the field width in the f-string.
阅读全文