How the heck can I do this… I’m New to Python and I’m trying to create a recipe catalog program to store all my recipes…
The ‘adding a recipe’ part of my code:
JavaScript
x
6
1
def add_recipe():
2
recipe_name = input ("Recipe name: ");
3
print('Please add the directions AND ingredients')
4
with open (recipe_name + ".txt", "x") as f:
5
f.write(input ());
6
I just need the Multi-line user input…
EDIT: I need it to go into a .txt file
Advertisement
Answer
You can use iter(input, '')
to accept input until a blank line:
JavaScript
1
6
1
recipe_name = input ("Recipe name: ");
2
print('Please add the directions AND ingredients')
3
with open (recipe_name + ".txt", "x") as f:
4
for line in iter(input, ''):
5
f.write(line + 'n');
6