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

Python Programming Help (Basic Level)


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!

  • Hydration 1
Link to post
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.

  • Hydration 1
  • Upvote 3
Link to post
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 post
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
  • Hydration 1
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...