+ 1

3rd Day Coding Question

Hello I have started to study python and just coding in general this week. I started going over just the beginning courses (literal 3 days long at programming in general.) Decided to step off into my own side project to bring all the beginning stuff I learned together, with a little bit of googling for the else/if, by making a simple "Math Genius" encounter. My issue is: I have y=input() print (y) thinking that it will print y as an equation for python to solve and print the answer... I guess not haha... ha is there a way to get python to read the input for y as an equation and solve it? here is my whole code so far print ('Hello! I am a math genius! Is there a problem I could help you with? (Yes or No)') x = str(input()) if x in ('yes','Yes','y','Y','YES'): print ('Great! What is your problem!') y = input() print (y) else: print('Well then you\'re my problem!') exit

12th Oct 2021, 7:04 PM
Michael Prieto
Michael Prieto - avatar
7 odpowiedzi
0
yes exactly ! so instead of priting 10+2 im trying to get it to print the solution. So im trying to get it to just print 8
12th Oct 2021, 7:32 PM
Michael Prieto
Michael Prieto - avatar
+ 3
Where did you tested your attempt? Becsuse your code works fine here: With input example: yes wetter Or another input: no https://code.sololearn.com/czuPMs8NtgPu/?ref=app
12th Oct 2021, 7:11 PM
JaScript
JaScript - avatar
+ 3
Here this works too. I got in above mentioned code the andwer: Hello! I am a math genius! Is there a problem I could help you with? (Yes or No) Great! What is your problem! 10+2
12th Oct 2021, 7:27 PM
JaScript
JaScript - avatar
+ 2
An input you can give in the terminal which should open when the code is running in visual studio code
12th Oct 2021, 7:30 PM
JaScript
JaScript - avatar
+ 1
For the second input i was testing writing it out as an equation so first input being yes second input being a problem like '10+2' and then having python take the second input and providing a solution over just printing the equation. I am testing in visual code studio with the python extensions i did get the yes no responses to work correctly :D
12th Oct 2021, 7:22 PM
Michael Prieto
Michael Prieto - avatar
+ 1
The eval() function might do what you want. print(eval(y))
14th Oct 2021, 10:05 AM
Brian
Brian - avatar
+ 1
Thank you so much Brian! Thats Exactly what i was looking for!
17th Oct 2021, 5:47 PM
Michael Prieto
Michael Prieto - avatar