Jump to content
The Official Site of the Vancouver Canucks
Canucks Community

Python Programming Help (Basic Level)


Dazzle

Recommended Posts

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!

  • Cheers 1
Link to comment
Share on other sites

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.

  • Cheers 1
  • Upvote 3
Link to comment
Share on other sites

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

    } 

  • Upvote 2
Link to comment
Share on other sites

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.

  • Thanks 1
  • Cheers 1
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...