Before lunch, follow the code in the book for a while -- hunt the first wumpus version

Source: Internet
Author: User

When you are free, start training ~~~~ It's a pleasure to move your head up .... :)

Learn Python once.

from random import choicecave_numbers = range(1,21)wumpus_location = choice(cave_numbers)player_location = choice(cave_numbers)while player_location == wumpus_location:    player_location = choice(cave_numbers)print "Welcome to Hunt the Wumpus!"print "You can see ", len(cave_numbers), "caves"print "To play, just type the number"print "of the cave you wish to enter next"while True:    print "You are in cave ", player_location    if (player_location == wumpus_location - 1 or        player_location == wumpus_location + 1):        print "I smell a wumpus!"    print "Which cave next?"    player_input = raw_input(">")    if (not player_input.isdigit() or        int(player_input) not in cave_numbers):        print player_input, "is not a cave!"    else:        player_location = int(player_input)        if player_location == wumpus_location:            print "Aargh! you got eaten by a wumpus!"            break

Before lunch, follow the code in the book for a while -- hunt the first wumpus version

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.