如何从列表中获取随机对象,每个对象只能获取一次?

时间:2014-10-01 15:34:56

标签: python list boolean

因此,我正在进行一项测验,让您获得一个国家并要求命名其资本。它可以工作,但你可能会被连续两次或每次游戏多次问同样的问题。我希望每个国家每场比赛只能被问到一次。我尝试了一个布尔值列表(?),' Not_used'列表,其中的想法是,当问题得到正确回答时,它将被设置为False并且不再出现。我不工作。我不知道该怎么做。

import random

hiscore = 46

points = 0

go_on = True

name = 'Mari'

Country = (['Norge', 'Sverige', 'Danmark', 'Island', 'Finland', 'Estland', 'Russland', 'Tyskland', 'Belgia',
        'Latvia', 'Litauen', 'Nederland', 'Frankrike', 'Spania', 'Portugal', 'Italia',
        'Sveits', 'Liechtenstein', 'Monaco', 'USA', 'Ukraina', 'Serbia', 'Kro5atia', 'Bosnia',
        'Hellas', 'Sør-afrika', 'Den demokratiske republikken Kongo', 'Algerie', 'Egypt', 'Somalia', 'Elfenbenskysten',
        'India', 'Kina', 'Mongolia', 'Sør-korea', 'Indonesia', 'Australia', 'Fillipinene',
        'Canada', 'Mexico', 'Peru', 'Kuba', 'Nicaragua', 'Argentina', 'Brasil', 'Chile','Bulgaria','Botswana','Fiji',
        'Georgia','Israel','Liberia','Albania','Andorra','Armenia','Aserbajdsjan','Bangladesh',
        'Belize','Bhutan','Benin','Brunei','Burkina Faso', 'Etiopia','Forente Arabiske emirater','Gabon','Gambia','Guinea',
        'Guinea-Bissau','Haiti','Iran','Irak','Japan','Kamerun','Kasakhstan','Kirgisistan','Komorene','Lesotho',
        'Mali','Myanmar','Nepal','Oman','Qatar'])

Capital = (['Oslo', 'Stockholm', 'København', 'Reykjavik', 'Helsinki', 'Tallin', 'Moskva', 'Berlin', 'Brussel',
             'Riga', 'Vilnius', 'Amsterdam', 'Paris', 'Madrid', 'Lisboa', 'Roma',
             'Bern', 'Vaduz', 'Monaco', 'Washington DC', 'Kiev', 'Beograd', 'Zagreb', 'Sarajevo',
             'Athen', 'Pretoria', 'Kinshasa', 'Alger', 'Kairo', 'Mogadishu', 'Yamoussoukro',
             'New Delhi', 'Beijing', 'Ulan Bator', 'Seoul', 'Jakarta', 'Canberra', 'Manila',
             'Ottawa', 'Mexico By', 'Lima', 'Havanna', 'Managua', 'Buenos Aires', 'Brasilia',
             'Santiago de Chile','Sofia','Gaborone','Suva','Tbilisi','Jerusalem','Monrovia',
             'Tirana','Andorra la Vella','Jerevan','Baku','Dhaka','Belmopan','Thimpu','Porto-Novo','Bandar Seri Begawan',
             'Ouagadougou','Addis Abeba','Abu Dhabi','Libreville','Banjul','Conakry','Bissau','Port-au-Prince','Teheran',
             'Bagdad','Tokyo','Yaounde','Astana','Bisjkek','Moroni','Maseru','Bamako','Naypyidaw','Katmandu','Muskat','Doha'])


print('Welcom to Capital Quiz!')

print('Remember Uppercase!')

print('Tyy to beat the hiscore =', hiscore,)

print(name,'is the current cahmpion')

k = input("To start press enter")


while go_on:

    print('-----------------------------------------------------------------------------')

    nr = random.randint(0,80)

    i = input('What is the capital of'+Country[nr]+'? ')

    Not_used = ([True, True, True, True, True, True, True, True, True, True,
                 True, True, True, True, True, True, True, True, True, True,
                 True, True, True, True, True, True, True, True, True, True,
                 True, True, True, True, True, True, True, True, True, True,
                 True, True, True, True, True, True, True, True, True, True,
                 True, True, True, True, True, True, True, True, True, True,
                 True, True, True, True, True, True, True, True, True, True,
                 True, True, True, True, True, True, True, True, True, True,
                 True])

    if i == Capital[nr]:
        points +=1
        Not_used[nr] = False
        print('Correct!')
        print('You currently have',points,'points.')    
    elif i != Country[nr]:
        poeng -=1
        print('-----------------------------------------------------------------------------')
        print('Worng, the capital of '+Country[nr]+' is ', Capital[nr],'.',sep='')
        go_on = False

print('Did you remeber uppercase?')

print('You scored',points,'points.')

if points > hiscore:

    print('You beat the hiscore! Congratulations!')

elif points < hiscore:

          print('Try to beat the hiscore = ', hiscore,'?', sep='')

          print('Try again!')

0 个答案:

没有答案