![]() |
input vs string - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: input vs string (/thread-13428.html) |
input vs string - thdnkns - Oct-15-2018 Hi, so I'm stuck on an assignment iterating words onto seperate lines and the code works when I just fill the variable with a string, but the second I put that string into an input, it just prints the input. Could someone possibly shed some light on why that happens? Here's the code: quote = "quote goes here" word = "" for letter in quote: if letter.isalpha(): word += letter else: if word > "": print(word.upper()) word = "" else: word = "" print(word.upper())And it works fine, but if I define quote with an input of the same string it just prints the string. Thanks! RE: input vs string - ichabod801 - Oct-15-2018 Please use Python tags when posting code (see the BBCode link in my signature below for instructions). I did them for you this time. So, are you saying that you tried quote = input("quote goes here") , and it just printed the quote? Because what input does is print the string passed to it, and then wait for the user to input a string. The user's input is then returned by input (in this case it would be assigned to the quote variable). After it prints, try typing something in and hitting return.
RE: input vs string - marienbad - Oct-15-2018 How are you inputting the string from the user? I used raw_input("enter text: ") and it worked. quote = raw_input("enter text: ") word = "" for letter in quote: if letter.isalpha(): word += letter else: if word > "": print(word.upper()) word = "" else: word = "" print(word.upper()) RE: input vs string - thdnkns - Oct-15-2018 (Oct-15-2018, 02:01 AM)ichabod801 Wrote: Please use Python tags when posting code (see the BBCode link in my signature below for instructions). I did them for you this time. Ya my bad, I'm still pretty new to this. I did what you said and nothing happens. It works when I just assign the string to quote though. (Oct-15-2018, 02:23 PM)marienbad Wrote: How are you inputting the string from the user? I used raw_input("enter text: ") and it worked.I'm using input(). Tried using raw_input and it throws off NameError: "name 'raw_input' is not defined".quote = raw_input("enter text: ") word = "" for letter in quote: if letter.isalpha(): word += letter else: if word > "": print(word.upper()) word = "" else: word = "" print(word.upper()) quote = raw_input("Wheresoever you go, go with all your heart") word = "" for letter in quote: if letter.isalpha(): word += letter else: if word[0].lower() >= "": print(word.upper()) word = "" else: word = "" print(word.upper()) RE: input vs string - marienbad - Oct-15-2018 ok, sorry, I am still on python 2.7. raw_input is now input in python 3, and like I said, it worked for me, so I can't see why it doesn't work for you. Try putting quotes around the text you are inputting. RE: input vs string - ichabod801 - Oct-16-2018 Then I'm not sure what's going on. It works for me with raw_input in 2.7 and input in 3.6. |