这是我当前的代码,但是输入不会更改为整数,有人能帮我吗
score = [0,20,40,60,80,100,120]
def validate_credits(input_credits):
try:
input_credits = int(input_credits)
except:
raise ValueError('integer required')
if input_credits not in score:
raise ValueError('out of range')
while True:
try:
mark1 = input('Enter your total PASS marks: ')
validate_credits(mark1)
mark2 = input('Enter your total DEFER marks: ')
validate_credits(mark2)
mark3 = input('Enter your total FAIL marks: ')
validate_credits(mark3)
except ValueError as e:
print(e)发布于 2022-11-16 04:23:37
这是一个范围界定的问题。考虑:
def the_function(_the_input):
_the_input = int('2')
if __name__ == "__main__":
the_input = '1'
the_function(the_input)
print(the_input)你认为the_input会是什么?'1‘或2’?
输出为'1'
一份名单怎么样?
def the_function(_the_input):
_the_input.append('2')
if __name__ == "__main__":
the_input = ['1']
the_function(the_input)
print(the_input)输出为['1', '2']
冒着没有正确解释这个问题的风险,我建议你去看this thread on the topic
要将输入作为整数,需要返回以下值:
def the_function(_the_input):
# + other function logic...
return int(_the_input)
if __name__ == "__main__":
the_input = '1'
the_input = the_function(the_input)
print(the_input)https://stackoverflow.com/questions/74455059
复制相似问题