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 Respostas
+ 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