# How do i get new lines in a text file if the variables are an input type

**URL:** <https://discuss.python.org/t/how-do-i-get-new-lines-in-a-text-file-if-the-variables-are-an-input-type/26476>\
**Category:** Python Help\
**Tags:** help\
**Created:** [May 4, 2023, 8:11am UTC](https://discuss.python.org/t/how-do-i-get-new-lines-in-a-text-file-if-the-variables-are-an-input-type/26476 "2023-05-04T08:11:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![maginagar](https://avatars.discourse-cdn.com/v4/letter/m/22d042/32.png) [@maginagar](https://discuss.python.org/u/maginagar)\
**Post date:** [May 4, 2023, 8:11am UTC](https://discuss.python.org/t/how-do-i-get-new-lines-in-a-text-file-if-the-variables-are-an-input-type/26476/1 "2023-05-04T08:11:38Z")

</div>

```python
    # YOUR CODE GOES HERE
a='introduction\n'
b=input("name \n")
c=input("voorname\n")
rapport=open("rapport.txt", 'w').writelines(a)
rapport=open("rapport.txt", 'a').writelines(b)
rapport=open("rapport.txt", 'a').writelines(c)

```

---

<div class="post-metadata">

**Author:** ![franklinvp](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/franklinvp/32/11142_2.png) [@franklinvp](https://discuss.python.org/u/franklinvp)\
**Post date:** [May 4, 2023, 11:37am UTC](https://discuss.python.org/t/how-do-i-get-new-lines-in-a-text-file-if-the-variables-are-an-input-type/26476/2 "2023-05-04T11:37:53Z")

</div>

Add the new line character. Also, you could open the file once.

```python
a='introduction\n'
b=input("name \n")
c=input("voorname\n")
with open('rapport.txt', 'w') as infile:
  infile.writelines(_ + '\n' for _ in (a, b, c))

```

---

<div class="post-metadata">

**Author:** ![maginagar](https://avatars.discourse-cdn.com/v4/letter/m/22d042/32.png) [@maginagar](https://discuss.python.org/u/maginagar)\
**Post date:** [May 4, 2023, 12:02pm UTC](https://discuss.python.org/t/how-do-i-get-new-lines-in-a-text-file-if-the-variables-are-an-input-type/26476/3 "2023-05-04T12:02:50Z")

</div>

Thanks you so much

---

<div class="post-metadata">

**Author:** ![kknechtel](https://avatars.discourse-cdn.com/v4/letter/k/e47c2d/32.png) [@kknechtel](https://discuss.python.org/u/kknechtel)\
**Post date:** [May 6, 2023, 1:50am UTC](https://discuss.python.org/t/how-do-i-get-new-lines-in-a-text-file-if-the-variables-are-an-input-type/26476/4 "2023-05-06T01:50:36Z")

</div>

There isn’t a separate “input type”. Using the `input` function gives you a perfectly ordinary string. The issue is because this string doesn’t have a newline at the end. In your code example, the string named `a` has a newline at the end, because it was written right there in the string literal: `'introduction\n'`. But `input` will not leave a newline at the end of the string that it reads, so you have to add one yourself.
