Dazzle Posted January 18, 2020 Share Posted January 18, 2020 Hello: I am trying to make a program where the value of a variable (example: +age) can be used to do math. So let's say I ask someone for their age. I want to make a program that does math BASED on that answer. How do I do this? Any help would be appreciated. Thanks! 1 Link to comment Share on other sites More sharing options...
goalie13 Posted January 18, 2020 Share Posted January 18, 2020 I took a course last year that included Python. I haven't touched it since, but here's a website we were using as a reference in class: https://learnpythonthehardway.org/python3/ 1 1 Link to comment Share on other sites More sharing options...
-SN- Posted January 18, 2020 Share Posted January 18, 2020 Super simple easy to break way: ageVariable = int(input("Enter an age")) print(f"Age is {ageVariable}") Use input to get the age, and use the int function to convert it to an integer right away, so you can perform calculations. Print it out using an f-string so you concatenate a string and int together. 1 3 Link to comment Share on other sites More sharing options...
Mathew Barzal Posted January 18, 2020 Share Posted January 18, 2020 10 minutes ago, StealthNuck said: Super simple easy to break way: ageVariable = int(input("Enter an age")) print(f"Age is {ageVariable}") Use input to get the age, and use the int function to convert it to an integer right away, so you can perform calculations. Print it out using an f-string so you concatenate a string and int together. Just to elaborate further, you can use that ageVariable in conjunction with an 'if' statement to do your math based on the answer you get. Not savvy with Python syntax but essentially, If (ageVariable < 40) { // do math } 2 Link to comment Share on other sites More sharing options...
Dazzle Posted January 19, 2020 Author Share Posted January 19, 2020 17 hours ago, StealthNuck said: Super simple easy to break way: ageVariable = int(input("Enter an age")) print(f"Age is {ageVariable}") Use input to get the age, and use the int function to convert it to an integer right away, so you can perform calculations. Print it out using an f-string so you concatenate a string and int together. 17 hours ago, Mathew Barzal said: Just to elaborate further, you can use that ageVariable in conjunction with an 'if' statement to do your math based on the answer you get. Not savvy with Python syntax but essentially, If (ageVariable < 40) { // do math } Very nice guys! Thank you very much. 1 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now