Python in Education


  |  Chapter 3: Why Python in Education?



Download 3,73 Mb.
Pdf ko'rish
bet25/37
Sana01.01.2022
Hajmi3,73 Mb.
#303345
1   ...   21   22   23   24   25   26   27   28   ...   37
Bog'liq
Python in Education (en)

18  |  Chapter 3: Why Python in Education?


        'exits': {

            'north': 'gatehouse',

        },

    },


}

# Set a default starting point.

place = 'cave'

# Start the game "loop" that will keep making new turns.

while True:

    # Get the current location from the world.

    location = world[place]

    # Print the location's description and exits.

    print(location['description'])

    print('Exits:')

    print(', '.join(location['exits'].keys()))

    # Get user input.

    direction = input('Where now? ').strip().lower()

    # Parse the user input...

    if direction == 'quit':

        print('Bye!')

        break  # Break out of the game loop and end.

    elif direction in location['exits']:

        # Set new place in world.

        place = location['exits'][direction]

    else:

        # That exit doesn't exist!

        print("I don't understand!")

A typical “game” (including user input) looks something like this:

$ python adventure.py

You are in a mysterious cave.

Exits:

up

Where now? up



You are in the castle courtyard.

Exits:


south, down

Where now? south

You are at the gates of a castle.

Exits:


south, north, up

Where now? hello

I don't understand!

You are at the gates of a castle.

Exits:

south, north, up



Where now? quit

Bye!



Download 3,73 Mb.

Do'stlaringiz bilan baham:
1   ...   21   22   23   24   25   26   27   28   ...   37




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish