小编use*_*523的帖子

我如何改变我的代码以打印出他们得到的答案是对还是错?

我需要这个程序来打印出你是对错的猜测数量.我有一个城市和国家的字典(称为ccdict),例如"英国":"伦敦".这是代码:

def choices (Correct):
    list=[Correct]
    f=0
    cities=ccdict.values()
    while f + 1<5:
        f=f+1
        list.append(cities[random.randint(0, len(cities))])
    list.sort()
    return list


countries = ccdict.keys()
randcountry = countries[random.randint(0, len(countries))]
print "What is the capital of " + randcountry + "?"
print "If you want to stop this game, type 'exit'"
randlist = choices(ccdict[randcountry])

for i in range(0,5):
        print str(i+1) + " - " + randlist[i]

input=raw_input("Give me the number of the city that you think is the capital of " + randcountry + " ") …
Run Code Online (Sandbox Code Playgroud)

python dictionary

-1
推荐指数
1
解决办法
136
查看次数

如何检查raw_input == python中的某些内容?

这就是我写的,你能不能看看我的代码有什么问题.我只是Python的初学者.

#!/usr/bin/python

input=int(raw_input("Write exit here: "))

if input==exit:
    print "Exiting!"
else:
    print "Not exiting!"
Run Code Online (Sandbox Code Playgroud)

python

-8
推荐指数
1
解决办法
296
查看次数

标签 统计

python ×2

dictionary ×1