i've been having trouble figuring this out since im new to python and i really wanna figure it out!

Write a Sentinel controlled While loop that allows the user to enter text until they enter ! by itself.

Output would be like this:
Enter some text: Hi
Enter some text: ThisIsFun
Enter some text: Bye Now
Enter some text: !
HiThisIsFunBye Now!

Heres what i have to far.

user = 0
total = 0

text =str(input("Enter some text "))

while total != 1:
    total = text + 1

Edited 4 Years Ago by layneb131: n/a

What are you using the 'user' variable for? You should use raw_input to set the 'text' variable and if you want it to be called more than once you have to put it inside the while loop.. something like this:

total = 0
text = ''
while text != '!':
   total += 1
   text = raw_input('Enter some text\n')

i was just basing this off an example in a python book i have. thanks for you help.

the code is getting a little closer now, i just dont have any idea what to change. this is the output:

Enter a number 1
Loops Are Neat!
Enter some text
Enter some text
Whats up
Enter some text
how are you
Enter some text

its supposed to not have the numbers, and it stores the text until ! is typed then it prints all of the text.

def sentinel(s='!'):
    t = inp = raw_input('Enter some text: ')
    while inp != s:
        inp = raw_input('More text: ')
        t += inp
    return t

if __name__ == '__main__':

Edited 4 Years Ago by pyTony: n/a

This article has been dead for over six months. Start a new discussion instead.