I have a def function looks like:
def update(marks, num, mark, column):
lines = [l for l in marks]
for row in range(len(all_marks)):
if all_marks[row][0] == num:
lines[row][column] = mark
elif lines[row][column] != '':
print num + ' already has a value in column - update ignored.'
and raw_input function inside another def function looks like:
result1 = raw_input('Enter results file: ')
num = raw_input('Student number (empty to finish): ')
if len(snumber) == 0:
print
print
print 'finished'
print
print
return interact()
else:
pass
column2 = raw_input('Enter column: ')
newresult1 = raw_input('New result: ')
try:
print update(result1, snumber, newresult1, column2)
except IOError:
print 'Try again'
The third line from the bottom supposed to print def update(marks, num, mark, column) but it keeps returning none.
Sorry, the codes are a bit messy. Can anyone let me know what I have done wrong?
Thanks in advance.
Your update
function doesn't look like it returns anything. You need to explicitly return something or there won't be a return value.
raw_input()
prompts the user and returns the user's response as a string . You're probably looking to convert the string into an integer.
This code will nag the user until a proper response is given:
while True:
try:
column2 = int(raw_input('Enter column: '))
break
except ValueError:
print 'You did not supply an integer!'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.