Reputation: 5
I need help to create a function that generates 8 digit random numbers with 2 favorite number sequencing anywhere.
def favourite_number(first, second):
phone = random.randint(600000,699999)
generate = first,second,phone
return generate
print(favourite_number(8,6))
This is the result I am getting but I want it to be randomly placed anywhere not compulsorily in the beginning and that too without comma.
"C:\Users\WIN Ultimate\PycharmProjects\new\venv\Scripts\python.exe" "C:/Users/WIN Ultimate/PycharmProjects/new/Numbergenerator.py"
(8, 6, 699936)
Upvotes: 0
Views: 82
Reputation: 780688
Use a list instead of tuple, so you can insert in a random index.
def favourite_number(first, second):
phone = random.randint(600000,699999)
generate = [first, second]
generate.insert(random.randint(0, 2), phone)
return generate
If you want to print it without commas, use:
print(" ".join(map(str, favourite_number(8, 6))))
Upvotes: 1
Reputation: 1054
I think that this is what you're looking for (:
import random
def favourite_number(first, second):
phone = random.randint(600000,699999)
generate = first,second,phone
generate = [str(x) for x in generate]
return ''.join(generate)
print(favourite_number(8,6))
There are many more ways to do it!!
Upvotes: 1