我在网上找不到任何东西,所以我想知道是否有人能帮忙。我有以下代码:
x = str(input("Enter number of unique customers then press enter: "))
我希望它然后向用户询问用户输入的客户数量。例如,假设用户输入"2"。我想问:客户1的号码?客户2的号码?
我找不到一种方法来看待变量x,并用它的答案来知道该问多少。谢谢
我认为您需要循环:
num = int(input('How many customers there are?')
list_customer = []
for i in range(num):
a = input('number for customer x')
list_customer.append(a)
print(list_customer[0]) # Number for customer 1
print(list_customer[1]) # Number for customer 2
我认为这就是你想要做的。它需要输入客户数量。制作一个列表,然后遍历该列表以获得该客户编号的输入。并将其转储到CCD_ 1数据帧中
import pandas as pd
results = pd.DataFrame()
x = str(input("Enter number of unique customers then press enter: "))
list_of_cust = list(range(0, int(x)))
for i in list_of_cust:
x2 = str(input("Enter number for customer %d: " %(i+1)))
temp_df = pd.DataFrame([[str(i+1), x2]], columns=['cust_no','value'])
results = results.append(temp_df).reset_index(drop = True)