Number Series - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Number Series (/thread-15431.html) Pages:
1
2
|
Number Series - MrGoat - Jan-17-2019 This was the given question : Write a Python program that prints all the numbers from 0 to 6 except 3 and 6. Note : Use 'continue' statement. Expected Output : 0 1 2 4 5 This is my code : for i in range(6): if i == 3: continue elif i == 6: continue else print iand error output : Please advise thanks
RE: Number Series - stullis - Jan-17-2019 If that's on line five, what's above it? Often times, syntax errors result from missing brackets above the point where the error is noted. RE: Number Series - perfringo - Jan-17-2019 Some observations: - range(6) is 0, 1, 2, 3, 4, 5 so no need to check i == 6 (or you should use range(7) )- else misses : (parenthesis) - is it Python 2? In Python 3 you need to use print(i) RE: Number Series - MrGoat - Jan-17-2019 It still doesnt work and gives the same error : the error is in the first line of the code " for i in range(7): " , but i can't see what's wrong with it ! for i in range(7): if i == 3: continue elif i == 6: continue else: print(i)Output error :
RE: Number Series - perfringo - Jan-17-2019 In snippet you provided this is row #1. Error message states that this is actually row #5. What is on previous four rows? RE: Number Series - MrGoat - Jan-17-2019 (Jan-17-2019, 10:22 AM)perfringo Wrote: In snippet you provided this is row #1. Error message states that this is actually row #5. What is on previous four rows? Nothing ... there is nothing on the previous 4 rows, really weird .... RE: Number Series - perfringo - Jan-17-2019 Do you use shebang in you .py file? Your problem description seems to be similar to the one in StackOverflow RE: Number Series - MrGoat - Jan-17-2019 (Jan-17-2019, 01:49 PM)perfringo Wrote: Do you use shebang in you .py file? No (Jan-17-2019, 01:55 PM)MrGoat Wrote:(Jan-17-2019, 01:49 PM)perfringo Wrote: Do you use shebang in you .py file? Still doesnt work whether I use shebang or not RE: Number Series - Axel_Erfurt - Jan-17-2019 I have no problem with your code, it works. Which editor do you use to save Qn8.py? RE: Number Series - hbknjr - Jan-17-2019 (Jan-17-2019, 01:55 PM)MrGoat Wrote: Still doesnt work whether I use shebang or not (Jan-17-2019, 05:53 AM)MrGoat Wrote: Without python shebang your command bash Question8.py will run it as a bash script.Try python Question8.py or use proper python2 shebang.
|