Function with input prints out nothing

别说谁变了你拦得住时间么 提交于 2019-12-24 12:17:57

问题


Ok so I'm trying to get z.ExNote() to print out an image (of an 8th note) onto a page of sheet music for an app I'm building. Basically every variable just has to do with the (x,y) coordinates of where the note is to be placed. .ExNote() is a function inside a class Note which translates 5 variables of the Note object (Num, staff, measure, note, notetype) into an x,y coordinate for the image to be placed on. This whole mess takes care of 4 variables for you so you can theoretically input the note c,d,e,f,g,a,b and it will print it out at the beginning of the staff, then the next note you input will be the next position which happens to be 17 pixels to the right and so on.

StaffL = {0: 'nada', 1: '1R', 2: '1L', 3:'2R',
      4: '2L', 5: '3R', 6: '3L', 7: '4R', 8: '4L'}

pygame.display.set_caption("Piano App")

done = False
clock = pygame.time.Clock()

while not done:

    clock.tick(10)

    for event in pygame.event.get(): 
        if event.type == pygame.QUIT: 
            done=True  



screen.fill(white)
DrawGrandStaffAll()
TS(4,4)
notetypeZ = 'Ethnote'
g=0
while g < 8:
    g+=1
    staff = StaffL[g]
    measureZ = 0
    while measureZ<6:
        measureZ += 1
        wnoteZ = 0
        while wnoteZ<8:
            wnoteZ += 1
            noteZ=(input("\n\nWhat note \nc\nd\ne\nf\ng\na\nb\nc2\nd2\n"))
            z = Note(int(wnoteZ), repr(staff), int(measureZ), repr(noteZ), repr(notetypeZ))
            z.ExNote()
            pygame.display.flip()
pygame.quit()

If I just type in what z ends up being equal to (Note(1, '1R', 1, 'c', 'Ethnote')) and then do z.Exnote(), it works(my note is printed onto the sheet music). But it doesn't work when I do it like this. I also ran this code in a separate window and printed out z to make sure it's not some technical error/typo and the output is exactly what I want it to be. So the problem isn't the variable and it's not some technical error. I'm assuming the error has something to do with the input because that's the only thing that changes between manually inputing z=Note(1, '1R', 1, 'c', 'Ethnote') and using this code to build the statement.


回答1:


Are you using Python 2 or 3. If you use Python 2, input() tries to evaluate the expression you type. raw_input() which I believe you want here returns the string.



来源:https://stackoverflow.com/questions/45408813/function-with-input-prints-out-nothing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!