Accept n inputs from your keyboard and form a tuple using for loop, don't limit the input to integer
时间: 2023-05-24 20:01:44 浏览: 63
类型,allow any input. Can you provide the code for this?
Sure, here's the code:
inputs = []
n = int(input("Enter the number of inputs: "))
for i in range(n):
inputs.append(input("Enter input #{}: ".format(i+1)))
t = tuple(inputs)
print("The tuple of inputs is:", t)
相关问题
Accept n inputs from your keyboard and form a tuple using for loop:
Sure, here's some Python code that accomplishes that:
```
inputs = []
n = int(input("How many inputs do you want to enter? "))
for i in range(n):
val = input("Enter input #{}: ".format(i+1))
inputs.append(val)
my_tuple = tuple(inputs)
print("Tuple: ", my_tuple)
```
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
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.