0

I want to be able to print the whole variable, or just detect it. If I run it through a for loop as I've done in the code below, it just prints the individual letters. How can it print the whole word?

Question = input()
Answer = input()

def test():
    for words in Answer:
        print(words)


test()
2
  • Answer.split() is what you are looking for Commented Jan 21, 2021 at 7:39
  • print(Answer)? Commented Jan 21, 2021 at 14:59

4 Answers 4

0

Since answer is a string, and a string is an enumerable type, it enumerates over the characters. If you want to print a plain string just do print(Answer).

Sign up to request clarification or add additional context in comments.

Comments

0

This would work perfectly

Question = input()
Answer = input()

def test():
    for words in Answer.split(' '):
        print(words)

test()

Comments

0

When you are iterating a string in python what it does, it makes an iterable out of a string and then it print's each letter in a given word. This is for both single word and multiple words, so either you can just print(Answer) or you can first split it by e.g. space and then print each word in a sentence like this:

answer = Answer.split()  # splits by space, you can provide any separator and this will generate a list for you
for word in answer:
    print(word)

This will print each word even if it's only 1.

Comments

0

This is a poorly phrased question and poorly researched question which can get you banned from asking questions in Stack overflow so keep that in mind when you post another question.

You can do

for word in Answer.split(" "):
    print(word)

If that's not what you are looking for you can try-

print(Answer)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.