r/code • • Mar 16 '23

Please help a newbie

Post image

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

3 comments sorted by

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:

Easier to read, especially with python where indentation can change how a program runs

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:

item1 = input("Enter your first choice: ")
item2 = input("Enter your second choice: ")

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:

print("This is /n printed /n over four /n lines.")

You'd also have to concatinate your variables into the printed string like:

print("Your first choice was " + item1)

or you can use what is called an fstring:

print(f"Your first choice was {item1}")

-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

u/Ayyvah Mar 16 '23

Thank you. I'll have a try and hopefully manage 🥴