Bottom Page

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
Quote
#2
Is that the full (verbatim) traceback?
It doesn't look like it.
Quote
#3
That was all I saw.
Quote
#4
The program if_ranner.py is local in directory: C:\Users\barbara\AppData\Local\Programs\Python\Python36-32
you should take a look at that because the error was from line 39 of that program
Quote
#5
it keeps showing me different errors sometimes when I run it.did you try running the python program over and over to see what happens.try running it tweleve times.
Quote
#6
i didn't try to run it at all.
The comment was made from looking at your traceback.
If you are receiving different errors, I would worry about some other reason, other than the code, perhaps some Mal software
amuck in your system.

Can you identify the program in your error message (if_ranner.py)?
buran likes this post
Quote
#7
what do you mean by," Can you identify the program in your error message (if_ranner.py)?"
instructions please.
Quote
#8
I had to lower
random.randrange(0,5)
to
random.randrange(0,4)
Quote
#9
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.")
The problem is, in some of your tuples you have such 4 elements rather than 5 (for instance timely tuple). But all your range function call seem to generate numbers between 0-5. Which will cause issues with the tuples which dont have the 5th element. Hence it worked when you changed from 5 to 4.
Quote
#10
thankyou.nice to know.I did not see that.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Can i prevent the random generator to generate already used numbers? MauserMan 3 116 Jan-05-2020, 04:44 PM
Last Post: MauserMan
  Random Password Generator with Weird Output. Why? Selenestica 2 234 Sep-11-2019, 04:36 AM
Last Post: Selenestica
  [split] Python beginner: Weird Syntax Error mnsaathvika 1 271 Jul-22-2019, 06:14 AM
Last Post: buran
  Sentence maker help bidoofis 2 454 Feb-08-2019, 03:59 AM
Last Post: bidoofis
  wont print last sentence.. mitmit293 2 356 Jan-27-2019, 05:38 PM
Last Post: aakashjha001
  Weird scoping error Stef 3 406 Jan-20-2019, 04:36 PM
Last Post: Stef
  PigLatin Sentence Translator Help 2skywalkers 7 1,569 Jun-23-2018, 12:46 AM
Last Post: 2skywalkers
  Weird error in pycharm TheRedFedora 1 765 Mar-11-2018, 09:01 PM
Last Post: Larz60+
  receive from a generator, send to a generator Skaperen 9 1,318 Feb-05-2018, 06:26 AM
Last Post: Skaperen
  Error Handling is weird PythonAndArduino 1 950 Nov-09-2017, 05:08 AM
Last Post: Mekire

Forum Jump:


Users browsing this thread: 1 Guest(s)