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

31st Jan 2023, 1:43 AM
ZeGermanJa
ZeGermanJa - avatar
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.
31st Jan 2023, 3:02 AM
Brian
Brian - avatar
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
31st Jan 2023, 6:46 AM
Lochard
Lochard - avatar