Jump to content

Python Printing Variables Inside of Text

BaconComputing

Hey guys! I've recently started programming in Python and I've run into an issue that's stumping me. I'm just messing around with if and for statements and I want to know how to state the numbers assigned to a variable inside of a printed text. Here's what I'm working with:

 
Jon = [9 , 10]
Sue = Jon
for i in Jon:
    Sue = i - 1
 
Right below the last line I would like to print("Sue could be [two variable values] years old.") How would I be able to insert the variable Sue into this text without going to the next line? 
Thanks,
-Bacon
Link to comment
Share on other sites

Link to post
Share on other sites

Jon = [9 , 10]Sue = Jonfor i in Jon:    Sue = i - 1Age = <whatever you calculate>print("Sue could be " + Age + " years old")

I think that should work. Wasn't sure what you're calculating though.

15" MBP TB

AMD 5800X | Gigabyte Aorus Master | EVGA 2060 KO Ultra | Define 7 || Blade Server: Intel 3570k | GD65 | Corsair C70 | 13TB

Link to comment
Share on other sites

Link to post
Share on other sites

Could you give an example of the output you want after adding in the variables,

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

Oh, actually I figured it out on my own. I just do %s, then after I close the print function I put % Sue.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×