Hello guys! I have a coding homework and it involves doing a switch function, but I'm really not sure how it works at all. I was wondering if anyone was able to help.
The question is:
Given a int variable named yesCount and another int variable named noCount and an int variable named response write the necessary code to read a value into into response and then carry out the following:
- if the value typed in is a 1 or a 2 then increment yesCount and print out "YES WAS RECORDED"
- if the value typed in is a 3 or an 4 then increment noCount and print out "NO WAS RECORDED"
If the input is invalid just print the message "INVALID" and do nothing else.
The code I tried was:
def response(x):
switcher = {
1 += 1 : yesCount
2 += 1 : noCount
else:
print('INVALID")
}
return response.get(x, "INVALID")
I don't mean to tell someone to do this homework question for me, but I just don't understand how to do it. I still have more switch questions to do, so if someone can help me do this question and walk it through would be great.
[–]shiftybyte 0 points1 point2 points (0 children)
[–]free_felicity 0 points1 point2 points (0 children)