0

Not sure if this is asked before but: How do you print "searching for x" where "x" is a random integer? I have my code below:

from random import randint

numbers = []
random = randint(1,50)

for i in range(0,10):
  numbers.append(randint(1,50))

for j in range(len(numbers)):
  print('searching for')
  print(random)
  print('in')
  print(numbers)
  break

And this is what happens but I want "searching for __ in [list]" on the same line. Is there a way to do it?

Thanks in advance!

Melodyyyyy
  • 13
  • 2

2 Answers2

0

try this:

print(f'searching for {random} in {numbers}')

it requires python 3.6 or up and it is called an f-string

Mirronelli
  • 740
  • 5
  • 14
0
for n in numbers:
  print("Searching for {} in {}".format(n, numbers))

Does that answer what you want to do?

HenriChab
  • 513
  • 1
  • 3
  • 10