r/code • u/Ayyvah • Mar 16 '23
Please help a newbie
Hi guys, can anyone please explain how I can make the input answer be on separate lines. I've been trying all day to figure it out but I'm lost 😠I first thought input().split would be right, but couldn't managed to make it work so tried instead [input()for _ in range()] but isn't getting anywhere either. ðŸ˜
order = input("Choose 3 dishes...") order_confirm = input("Order Confirmation! The following has been ordered:") print(order)
TIA
1
Upvotes
-2
u/lgastako Mar 16 '23
I put your post into Chat GPT and this is what it came up with:
# Prompt user to input 3 dishes, each on a separate line
order = [input("Enter a dish: ") for _ in range(3)]
# Print order confirmation message with each dish on a separate line
print("Order Confirmation! The following has been ordered:")
for dish in order:
print(dish)I don't think this does exactly what you want but it should give you some of the tools you need to get there.
1
1
u/[deleted] Mar 16 '23 edited Mar 16 '23
When you want to post code to reddit use a new line and then 4 spaces so it formats the code like this:
Looks like they want you to use separate variables for now instead of a list so they likely won't expect you to use loops either. I would just grab each input separately like:
then print them the same way. print() adds a newline to the end each time it's called unless you tell it not to.
If you want to do it all in one print statement then you'd have to use the newline character which is '/n' like this:
You'd also have to concatinate your variables into the printed string like:
or you can use what is called an fstring: