all you need to do is modify the print statement to insert the variables. You dont really need a function for an int as range() built-in returns a list of integers to the specified range.
You can alternatively skip the nested for loop and use itertools.product
>>> for x in range(1,5): ... for y in range(1,5): ... print(f'Hello{x} Bye{y}') ... Hello1 Bye1 Hello1 Bye2 Hello1 Bye3 Hello1 Bye4 Hello2 Bye1 Hello2 Bye2 Hello2 Bye3 Hello2 Bye4 Hello3 Bye1 Hello3 Bye2 Hello3 Bye3 Hello3 Bye4 Hello4 Bye1 Hello4 Bye2 Hello4 Bye3 Hello4 Bye4You can add a newline to print a space between them
>>> for x in range(1,5): ... for y in range(1,5): ... print(f'Hello{x} Bye{y}\n') ... Hello1 Bye1 Hello1 Bye2 Hello1 Bye3 Hello1 Bye4 Hello2 Bye1 Hello2 Bye2 Hello2 Bye3 Hello2 Bye4 Hello3 Bye1 Hello3 Bye2 Hello3 Bye3 Hello3 Bye4 Hello4 Bye1 Hello4 Bye2 Hello4 Bye3 Hello4 Bye4If you want the second number to always be 1
Bye1
then just ignore the nested loop y.You can alternatively skip the nested for loop and use itertools.product
>>> from itertools import product >>> r = range(1,5) >>> for x,y in product(r,r): ... print(f'Hello{x} Bye{y}') ... Hello1 Bye1 Hello1 Bye2 Hello1 Bye3 Hello1 Bye4 Hello2 Bye1 Hello2 Bye2 Hello2 Bye3 Hello2 Bye4 Hello3 Bye1 Hello3 Bye2 Hello3 Bye3 Hello3 Bye4 Hello4 Bye1 Hello4 Bye2 Hello4 Bye3 Hello4 Bye4
Recommended Tutorials: