Python Forum
weird error in random sentence generator
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
weird error in random sentence generator
#1
i put all the lists on top and the error still occurs.I am using python3.6.3 on windows 10.
sometimes i get this error sometimes not when i run this code over and over.
Error:
Traceback (most recent call last): File "C:\Users\barbara\AppData\Local\Programs\Python\Python36-32\if_ranner.py", line 39, in <module> print (people[morn] + ' ' + actions[morn] + ' ' + thesethings[morn] + ' ' + timely[morn]) IndexError: tuple index out of range
here is my python code

import random

print ("returns random element from list [10, 20, 30, 40, 50]) : ", random.choice([10, 20, 30, 40, 50]))
print ("returns random character from string 'Hello World' : ", random.choice('Hello World'))
b = ["sam went to the store", "bob visited jill", "billy went hunting"] 
print(random.choice(b))

nouns = ("alien", "man", "android", "girl", "monkey")
verbs = ("runs", "faints", "jumps", "trips", "barfs") 
adv = ("crazily.", "dutifully.", "foolishly.", "merrily.", "occasionally.")
adj = ("adorable", "clueless", "ignorant", "odd", "stupid")
nons = ("alien", "man", "android", "girl", "monkey")
vorbs = ("hunts", "walks", "jumps", "trips", "shoots gun") 
aev = ("slowly.", "carefully.", "fast.", "actiously.", "occasionally.")
ado = ("adorable", "clueless", "ignorant", "odd", "stupid")
humanoid = ("alien", "man", "android", "girl", "monkey")
done = ("hunts", "walks with", "pushes", "trips", "shoots at","traps") 
living = ("a alien", "a man", "a girl", "a android", "a monkey")
things = ("in a pit.", "in a tunnel.", "upstairs.", "downstairs.", "in the water.")
bipeds = ("alien", "man", "android", "girl", "monkey")
sports = ("goes golfing", "goes swimming", "goes skiing", "goes bowling", "goes surfing","goes hoverboarding") 
gowith = ("with a alien", "with a dog", "with a girl", "with a android", "with a robot")
time = ("in the morning.", "at lunch time.", "in the afternoon.", "at night time.")
people = ("girl", "woman", "man", "robot")
actions = ("sees", "yells at", "films", "talks to") 
thesethings = ("scary alien", "a deer", "the stormy sky", "women standing in the rain")
timely = ("in the morning.", "at lunch time.", "in the afternoon.", "at night time.")
nem = random.randrange(0,5)
print (nouns[nem] + ' ' + verbs[nem] + ' ' + adv[nem] + ' ' + adj[nem])
cob = random.randrange(0,5)
print (nons[cob] + ' ' + vorbs[cob] + ' ' + aev[cob] + ' ' + ado[cob])
nob = random.randrange(0,5)
print (humanoid[nob] + ' ' + done[nob] + ' ' + living[nob] + ' ' + things[nob])
mon = random.randrange(0,5)
print (bipeds[mon] +  ' '  + sports[mon] + ' ' + gowith[mon] + ' ' + time[mon])
morn = random.randrange(0,5)
print (people[morn] + ' ' + actions[morn] + ' ' + thesethings[morn] + ' ' + timely[morn])
Huh
Reply


Messages In This Thread
weird error in random sentence generator - by bobger - Nov-28-2017, 09:46 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Unknown Error with Random Stat Assigner FC8 6 2,298 Dec-06-2021, 01:56 PM
Last Post: FC8
  Random coordinate generator speed improvement saidc 0 2,047 Aug-01-2021, 11:09 PM
Last Post: saidc
  while sentence kimyyya 3 2,942 Mar-20-2021, 06:00 AM
Last Post: Pedroski55
  List / arrays putting in sentence Kurta 3 2,554 Dec-25-2020, 11:29 AM
Last Post: Larz60+
  How to make a telegram bot respond to the specific word in a sentence? Metodolog 2 6,341 Dec-22-2020, 07:30 AM
Last Post: martabassof
  Yield generator weird output Vidar567 8 3,257 Nov-23-2020, 10:59 PM
Last Post: deanhystad
  Random number generator charlottelol 5 3,196 Nov-10-2020, 10:51 PM
Last Post: deanhystad
  Weird function defaults error? wallgraffiti 5 2,149 Aug-07-2020, 05:55 PM
Last Post: deanhystad
  basic random number generator in replace function krug123 2 2,029 Jul-31-2020, 01:02 PM
Last Post: deanhystad
  How to match partial sentence in long sentence Mekala 1 1,522 Jul-22-2020, 02:21 PM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020