如果为True:?,则无法启动输入命令?。重要性和替代品,如果是真的:?

2024-09-29 19:04:36 发布

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

我在学Python3。前进,但输入命令困惑我,因为他们不启动自己?除了谷歌和youtube,我没有接受过这方面的正规教育。我知道我缺少一些基本的东西。你知道吗

我在www上看过了。请详细解释一下好吗?你知道吗

def take_input():
    print (" ")
    city = input("which city do you wish to travel to? \n Options are: delhi, kolkata, bombay, bengaluru : ")
    city.lower()
    print (" ")
    days = int(input("How many days are you travelling for? eg 1 - 100 : ")) 
    nights = days - 1
    print (" ")
    spending_money = int(input("How much spending money do you plan on carrying?, eg 100 - 10000 : "))
    return city, days, spending_money , trip_cost(city, days, spending_money)


# trying to collect user data


#remaining code removed for minimal reproducible question :)


while True: 
    take_input()

Tags: toyoucityforinputdaysdoare
1条回答
网友
1楼 · 发布于 2024-09-29 19:04:36

while True是Python的基础。 意思是“永远这样”。 对于永远运行且永不停止的项目来说,这一点很重要。 你可以用break来打破它。你知道吗

我来谈谈你的密码。您正在使用return,但是您没有对返回的变量执行任何操作。例如,您可以使用print()打印它们

示例:

def take_input():
    print (" ")
    city = input("which city do you wish to travel to? \n Options are: delhi, kolkata, bombay, bengaluru : ")
    city.lower()
    print (" ")
    days = int(input("How many days are you travelling for? eg 1 - 100 : ")) 
    nights = days - 1
    print (" ")
    spending_money = int(input("How much spending money do you plan on carrying?, eg 100 - 10000 : "))
    return city, days, spending_money , trip_cost(city, days, spending_money)


# trying to collect user data


#remaining code removed for minimal reproducible question :)


while True:
    myvar = ", "
    mylist = []
    for i in take_input():
        mylist.append(str(i))
    print("Returned values:",myvar.join(mylist))

相关问题 更多 >

    热门问题