如何停止重复字符串" MCI"在python中连续多次?

时间:2016-02-15 03:55:06

标签: python-3.5

我只是希望它出现在每个试验的开始时以及它到达不同的位置之后。不是连续的。

导入随机

while循环回到开头

虽然是真的:     试验= int(输入("您希望运行多少次试验?"))     如果试验< 0:         print("您必须输入一个大于0的值。")

elif trials>0:

for循环打印出每个试验

    count=0
    for x in range(trials):
        count+=1
        count_trials=print("The Trial is",count)

为每个机场分配一个号码
        while True:
            airports=random.randint(1,4)

            print("MCI -> ", end="")
            if airports==1:
                airports="MCI"


            elif airports==2:

                airports="LVS"

            elif airports==3:

                airports="SEA"

            elif airports==4:
                print("HNL")
                break

            count_hops=print(airports, end=" -> ")

1 个答案:

答案 0 :(得分:0)

我想你需要这个

import random

trials=int(input("How many trials would you like to run?"))
if trials <0:
    print("You must enter a value greater than 0.")
elif trials>0:
    count=1

true=True       

while true==True:
    airports=random.randint(1,4)
    print("trial no. ->"+str(count))
    if count>=trials:
        true=False

    if airports==1:
        airports="MCI"

    elif airports==2:
        airports="LVS"

    elif airports==3:
        airports="SEA"

    elif airports==4:
        airports="HNL"

    count+=1

    count_hops=print("airport"+" -> "+airports)

如果你无法理解某些内容或其不适当的内容,请添加评论