Python Forum
Completly lost about to fail my class!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Completly lost about to fail my class!
#8
Hope this helps.  It's not exactly what u were doing, but I built a tiny program to take in lyrics.  I imagine it's clunky and not necessarily efficient (u generally should not go more than 3 nests deep...this goes 4 deep early on actually) but it does the job.  It runs on python3 (I imagine this is what u are also using.) Run it initially using the input option to input your lyrics, then run it again using the load option to read them.
 this is the class file...save it as lyrics1cl.py
#lyrics1cl.py

class L():
    def __init__(self):
        self._lyric_list =[]
    def adding(self,item):        
        self._item = item
        self._lyric_list.append(self._item)
    def create_file(self,f):
        self.f = f + '.txt'
        with open(self.f, 'a+') as tf:
            for thing in self._lyric_list:
                tf.write(thing+'\n')
        tf.close
    def print_file(self,f):
        self.f = f+'.txt'
        with open(self.f) as tf:
            tf.seek(0)
            print(tf.read())
        tf.close
Below is the 'main' file that you will run ...save this as whatever you want... I suggest placing both in 1 folder.
The program will build a .txt file for your lyrics and the text file should pop up in the same folder...that way you won't have to run the program for the print out - if you don't want to - Python is considered the easiest to learn but at our stage Python can pi** us off occasionally and sometimes not interacting with it is lovely - hence the text file...if you are frustrated just open than up..
#lyrics1.py

from lyrics1cl import L

Song= L()

print('1] - input\n2] - load')
choice=input('choose one the above options.')

selection = True

while selection:
    if choice =='1' or choice =='input':
        enter_lyric=str(input('enter line below [enter- to stop].'))
        if enter_lyric == '':
            selection = False    
            savefile=str(input('hit [enter] to save your lyrics.'))
            if savefile== '':
                    new_file=str(input('enter filename (w/out ext).'))
                    Song.create_file(new_file)
                    view = str(input('hit [enter] to view lyrics.'))
            if view == '':
                Song.print_file(new_file)
        Song.adding(enter_lyric.strip())
    elif choice =='2' or choice =='load':
        enter_file=str(input('enter file name (w/out ext).'))
        Song.print_file(enter_file)
        break
    else:
        break

print('thx. Good bye.')   
I'm very much a noob like you.  I'm not a particularly big fan of interactive.  IMHO it's a great tool to quickly write/run/debug, but only when you are experienced enough with python syntax and only when you are comfortable enough to navigate things like traceback errors without the initial freakout (my heart certainly skips a beat with tracebacks). At our level, I don't think interactive is very helpful.  My preference is very much ide.
Reply


Messages In This Thread
RE: Completly lost about to fail my class! - by mepyyeti - Dec-28-2017, 11:50 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I am completely lost on this homework assignment a36 1 1,779 Feb-21-2022, 06:01 AM
Last Post: buran
  Very Lost vollynez 3 1,895 Oct-02-2020, 09:09 PM
Last Post: Yoriz
  I got lost in the program Gadev 1 1,903 Nov-11-2018, 05:50 PM
Last Post: j.crater
  I keep getting errors and I'm lost! samjonsnell 9 4,953 Oct-28-2018, 11:38 PM
Last Post: samjonsnell
  test..and I'm already lost sannixinc 1 2,526 Feb-22-2018, 09:09 PM
Last Post: glidecode

Forum Jump:

User Panel Messages

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