great, lets get started . let me begin by saying this is not schoolwork , this is a lazy Saturday on the couch experimenting with python and and trying to learn the basics.Mostly just trying to get a handle on for loops and if statements.So anyways i was just messing with a silly bit of code to demonstrate various concepts to myself and i came across an anomaly of sorts ( well to me anyway ) and an error that i cant seem to figure out .
ok lets look at the code:
def boom(): import time mylst= [1,2,3] y=str("boom!!!!!!!!!!!!!!!!!!!!!!!!!") print('hello this message self destructs in 3 seconds:') for anythngiwantcangohere in mylst: time.sleep(1) print(anythngiwantcangohere) for anything in y: print (y) boom() ans = input('would you like to boom again? y/n') if ans == 'y': boom() else: print('goodbye')
ok so the function works as expected but does contain the anomaly that 'boom!!!!!!!!!!!' is print on the screen ALOT of times. I'm pretty sure i dont understand what im doing here:
for anything in y: print (y)
ok thats the first bit , the error comes into play on line 17
i cant seem to get it to accept " y "as input
the error given is:
Traceback (most recent call last):
File "/home/mojo/test.py", line 17, in <module>
ans = input('would you like to boom again? y/n')
File "<string>", line 1, in <module>
NameError: name 'y' is not defined
so thats where im stuck at , any hints tips or tricks ???????