[Tutor] Help

travis jeanfrancois trvsjeanfrancois12 at gmail.com
Wed Mar 20 20:57:50 CET 2013


Hello, I am a beginning python student and I am having trouble with a
program I am writing  . The problem requires me to use "while" and that I
create a function that allows the user to a create sentence by  inputing  a
string and to end the sentence with a  period meaning inputing "." .The
problem is while keeps overwriting the previuos input and it still asks for
a string even after it prints out  .

Here is the output I am getting


Enter the first word in your sentence: I
Enter the next word in your sentence: am
Enter the next word in your sentence: a
Enter the next word in your sentence: novice
Enter the next word in your sentence: .
   I . .
Enter the next word in your sentence:


Here is the desired output:
                                                              :
Enter the first word in your sentence: I
Enter the next word in your sentence: am
Enter the next word in your sentence: a
Enter the next word in your sentence: novice
Enter the next word in your sentence: .
I am a novice.

Here is my code:





def B1():
 #Creates a function called B1
 period = "."
 # The variable period is assigned
 first = input("Enter the first word in your sentence ")
 #The variable first is assigned
 next1 = input("Enter the next word in you sentence or enter period:")
 #The variable next 1 is assigned

 # I need store the value so when while overwrites next1 with the next
input the previous input is stored and will print output when I call it
later along with last one
 # I believe the solution is some how implenting this expression x = x+
variable

 while  next1 != (period) :

    next1  = input("Enter the next word in you sentence or enter period:")

    if next1 == (period):
        next1 = next1 + period
        print ("Your sentence is:",first,next1,period)

PS : The" #"  is I just type so I can understand what each line does
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130320/0bb0c707/attachment.html>


More information about the Tutor mailing list