【发布时间】:2016-04-25 10:00:43
【问题描述】:
所以我的计算机科学老师给了我一个问题,但我已经坐在这里很久了,我一生都无法弄清楚。问题中有很多任务,但只有一个我遇到了麻烦。
所以,我正在为一家地毯店编写一个程序,而我坚持的部分就是这个。
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??
如果有人能解决这个问题,他们正在帮助我加载。谢谢:)
【问题讨论】:
-
你想要
numberOfRooms = int(input("blah blah"))而不是numberOfRooms = input(int("blah blah"))。您正在尝试将您的消息作为整数转换为用户,但实际上您希望将用户的响应转换为整数。 -
这是一个很好的例子,说明查看确切的错误输出可以提供信息。我猜你会得到一个
ValueError,但最好不要让我们猜测,通过添加确切的错误输出,它可以更容易地回答你的问题。查看stackoverflow.com/help/mcve 了解如何改进写作问题的信息。 -
我会,但代码没有有用的错误,因为我问的是如何继续它,而不是它有什么问题。不过还是谢谢:)
标签: python loops variables integer int