Cant randomize list with classes inside of it Python 2.7.4

2024/11/10 16:35:58

I am new to coding and I need some help. I'm trying to randomize these rooms or 'scenes' in a text adventure but whenever I try to randomize it they don't even show up when I run it! Here is the script:

from sys import exit
import time
import random
#import another file here to use in thisclass Scene(object):def enter(self):print "Not yet configured."class Start():def start(self):print "Hello. How are you? You are about to play a game that is set in a crazy world."print "We are creating your profile right now."epic = raw_input("Enter your name here: ")print "Hello, %s." % epicprint "You are being transported to a randomly generated world. Try to survive as long as possible."print "Here's some advice, %s: Don't die. Make the right choice. Be careful." % epicprint "The rules will be shown to you soon."print "LOADING..."time.sleep(1)return Rules().rules()class Rules(Scene):def rules(self):print ""print "-------------"print ""print "These are the rules:"print "1: Be a good sport. This game takes skill and memory to be able to win, so try your best to succeed."print "2: Every time you die, you do not get to respawn, so you will be prompted to either just not play anymore"print "or play again. If you decide to play again, you will most likely be on a new world with a new puzzles."print "3: Finally, have fun. Hopefully this game brings you joy, so have a great time playing it."return random.choice(the_shuffler)class BoilerRoom(Scene):def boiler_room(self):print "You are in the boiler room."class Kitchen(Scene):def kitchen(self):print "You are in the kitchen."class Pool(Scene):def pool(self):print "You are in the pool."class TennisCourts():def tennis_courts(self):print "You are in the tennis courts."class SoccerField():def soccer_field(self):print "You are on the soccer field."class Map(object):scenes = {Rules(): 'rules',BoilerRoom(): 'boiler_room',Kitchen(): 'kitchen',Pool(): 'pool',TennisCourts(): 'tennis_courts',SoccerField(): 'soccer_field'}the_shuffler = (BoilerRoom, Kitchen, Pool, TennisCourts, SoccerField)Start().start()
Answer

You need to call the method on the class returned by random.choice(the_shuffler).

It would help if each class had the description printing method named the same.

https://en.xdnf.cn/q/119483.html

Related Q&A

calculate the queue for orders based on creation and delivery date, by product group

I have a Pandas dataframe containing records for a lot of orders, one recorde for each order. Each record has order_id, category_id, created_at and picked_at. I need to calculate queue length for each …

Python print with string invalid syntax

I have a rock, paper, scissors code Ive been working on lately (yes, I am a total noob at coding), and I get an Invalid Syntax error with this specific line:print(The magical 8ball reads "Your for…

How to load images and text labels for CNN regression from different folders

I have two folders, X_train and Y_train. X_train is images, Y_train is vector and .txt files. I try to train CNN for regression. I could not figure out how to take data and train the network. When i us…

How to calculate number of dates within a year of a date in pandas

I have the following dataframe and I need to calculate the amount of ER visit Dates with a score of 1 that are one year after the PheneDate for that pheneDate for a given subject. So basically phenevi…

Remove substring from string if substring in list in data frame column

I have the following data frame df1string lists 0 i have a dog [fox, dog, cat] 1 there is a cat [dog, house, car] 2 hello everyone [hi, hello, everyone] 3 …

how to save data in the db django model?

Good day, I cant really understand what Im doing wrong in here. I was using this function base view to store my scrap data in the database with the django model, but now its not saving any more. I cant…

Move existing jointplot legend

I tried answers from a previous question to no avail in Matplotlib 1.5.1. I have a seaborn figure:import seaborn as sns %matplotlib inline import matplotlib.pyplot as plt import numpy as np tips = sns.…

timezone conversion of a large list of timestamps from an excel file with python

I have an excel file named "hello.xlsx". There is a column of timestamps that has a lot of rows (more than 80,000 rows for now). The file basically looks like this:03/29/2018 19:24:5003/29/20…

N_gram frequency python NTLK

I want to write a function that returns the frequency of each element in the n-gram of a given text. Help please. I did this code fo counting frequency of 2-gramcode:from nltk import FreqDistfrom nltk.…

Is there a way to have a list of 4 billion numbers in Python?

I made a binary search function and Im curious what would happen if I used it on 4 billion numbers, but I get a MemoryError every time I use it. Is there a way to store the list without this issue?