In this help sheet, we’ll approach this using both strings and f-strings. Here is the first part of the program with comments. (Go ahead and type it as you see it.)

Untitled

When we run this program, it will spit out an error.

Untitled

The error reads:

TypeError: can only concatenate str (not "int") to str

It’s important to understand this one as you’ll encounter it often. When you use a print statement, the entire line needs to be of a single variable type. (Either everything must be a string or everything must be an integer.)

In this line, we loaded a string value into the variable x:

x = input("pick a number between 1 and 100: ")

In this line, we loaded an integer value into the variable y:

y = random.randint(1,100)

In this line, then, we are trying to print a string and a variable at the same time.

Untitled

The solution when using ‘regular’ strings is this: We need to typecast the integer (y) to a string as seen below:

Untitled

The program should run without errors at this point.

Next, we will print this same line using an f-string. (Formatted String). You’ll see this syntax a lot.

Untitled

At this point, your program should look like this when run: