How do I include integers in a string in Python?

anaveragenoobie
import random


q = random.randint(10, 100)
w = random.randint(10, 100)
e = (q, " * ", w)
r = int(input(e))

This outputs (i.e):

>>> (60, ' * ', 24)

I tried following this post but I faced an error.

I want output to atleast look like:

>>> (60 * 24)

What I tried was doing

import random


q = random.randint(10, 100)
w = random.randint(10, 100)
**e = (q + " * " + w)**
r = int(input(e))

Which gave me the error.

Temba

A great way to do this is with f-strings

e = f"{q} * {w}"

You just need to start your string with an f, then include any variables in curly braces {}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I convert a list of integers to a string - Python

How do I iterate a counter and include it in a string replacement? (Python)

how do i include a string or an 'and' inside a list?

How do I parse a string of numbers into a array of integers?

How do I pad string representations of integers in Haskell?

How do I resolve "TypeError: string indices must be integers" error?

How do I fix "TypeError: string indices must be integers"

How do i loop through each entry in a string delimited by a comma and include it as a separate input using Python

How can i convert this string to integers & other strings in Python

How do I separate two integers from a string of those two integers?

How do i get all integers between two values in python?

How do I flatten a python list? Inputs are lists, strings or integers

How do I convert a list of strings to integers in Python

How do I convert a list of integers into an actual list in python

How do I include an image in a CDATA string which represents HTML?

How do I include curly braces in NSURL string?

How do I include a variable in a multidimensional JSON string?

How do I check for two words on a string using include()?

How do I include new lines in a string in Perl?

How do I include a string in an escape sequence in c#

How do I not include the first part of a Text String in my Regex?

How to identify the integers in a string in Python?

How do I add all integers in one list to integers on another list with different length in the same order in Python?

How can I make a Python string to include unicode code points?

How do I do big integers in Fortran?

How do I parse a string with both letters and integers into string and integer variables in VB.net?

How do I do make this string 2 integers using a regular expressions?

How do I add all include .h files in python directory

Python: How do I include a function in another function?