0
Need help creating addition function
Iām brand new to Python. One of the college courses Iām taking asked for a āconversation with a computerā program to be created. Iāve managed to get it to the point where it responds to user input by selecting random answers from the library. Where Iām stuck at is creating an addition function that adds the users integer input response to the defined integer of the ācomputerā. I canāt seem to figure it out. Any help would be greatly appreciated. https://code.sololearn.com/c1SK8NM8csM8/?ref=app
2 Answers
+ 2
ZeGermanJa it is hard to pinpoint what to advise you. It would help to see your attempted code, but as it stands it has no addition function.
Two ideas come to mind that you might find helpful:
1. A numeric entry from the input() function comes in as a string and must be converted to a numeric value. That can be done by using a conversion function such as int() or float().
2. If the user may enter a mathematical expression, then the entered string can be evaluated by using the eval() function.
0
Is this what you mean? (implemented in a bad way just for demo)
sample line of input that will trigger the addition:
5 dogs
https://code.sololearn.com/c00qp1emDYru/?ref=app