0

below is my codes. i would like to print the inputs but i want the codes to be shorter and not tedious. how do i print the 10 inputs i have typed in without repeating the word 'print' 10 times?

  Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, Q10= str(input("Enter answers separating by space: ")).split()

  print("Q1", Q1) 
  print("Q2", Q2) 
  print("Q3", Q3) 
  print("Q4", Q4) 
  print("Q5", Q5) 
  print("Q6", Q6) 
  print("Q7", Q7) 
  print("Q8", Q8) 
  print("Q9", Q9)
  print("Q10", Q10) 
  • You can do it in one line: print(Q1, Q2, Q3, Q4, Q5, Q6, Q7, Q8, Q9, Q10, sep="\n") [More info](https://www.geeksforgeeks.org/python-sep-parameter-print/) – DarrylG Dec 08 '19 at 13:01

1 Answers1

0

Use a list instead of separate variables

qs = str(input("Enter answers separating by space: ")).split()

for idx, a in enumerate(qs):
     print(f'Q{idx + 1} {a}')

Or one liner

print(*[f'Q{idx + 1} {a}' for idx, a in enumerate(qs)], sep='\n')
Guy
  • 46,488
  • 10
  • 44
  • 88