由用户输入的整数循环一个句子

2024-03-28 15:31:53 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我的计算机科学老师给了我一个问题,但是我已经在这里坐了很久了,一辈子都想不出来。问题中有很多任务,但只有一个我有问题。你知道吗

所以,我正在为一家地毯店编写一个程序,而我一直坚持的部分就是这个。你知道吗

2:对于需要铺地毯的每一层,请用户提供地板所在房间的名称。 基本上是X房间的数量;需要循环一个句子,要求用X乘以房间的名称。因此,如果用户有3个房间需要铺地毯,我最终会得到3个房间(休息室、卧室等)的名称,并能够稍后将这些结果显示给用户。这是我到目前为止得到的。。。你知道吗

#Generating An Estimate. 

#Welcome message + setting base price to 0 + defining "getting_estimate" variable.
def getting_estimate ():
    overallPrice = 0
    print("Welcome!")

#Getting the information about the customer.
    custID = input ("\n1. Please enter the customer's ID: ")
    estimateDate = input ("\n2. Please enter the date: ")
    numberOfRooms = input (int("\n3. Please enter the number of rooms that need to be carpeted: "))

#Add input allowing user to enter the 
#name of the room, looped by the integer entered
#in the Variable "numberOfRooms", and possibly
#adding 1st room, 2nd room etc??

如果有人能解决这个问题,他们就是在帮我。谢谢:)


Tags: theto用户名称inputcustomerroom房间
1条回答
网友
1楼 · 发布于 2024-03-28 15:31:53

也许使用for循环?你知道吗

    for i in range(numberOfrooms):
        roomName = input("Blah blah")

完整代码:

def getting_estimate ():
overallPrice = 0
print("Welcome!")

custID = input ("\n1. Please enter the customer's ID: ")
estimateDate = input ("\n2. Please enter the date: ")
numberOfRooms = int (input("\n3. Please enter the number of rooms that need to be carpeted: "))
cust_roster = {custID:[]}
for i in range(numberOfRooms):
    roomName = input("Enter the name of room number "+str(i+1))
    cust_roster[custID].append(roomName)
print("{} has {} rooms called: {}".format(custID,
                                          len(cust_roster[custID]),
                                          cust_roster[custID]))

顺便说一句,我正在为我的OCR计算课程做一个类似的任务;)祝你好运!你知道吗

相关问题 更多 >