Write a program that prompts for the user to input a sentence





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







-1
















Write a program that prompts for the user to input a sentence. Then check this sentence to make sure the first word of the sentence is capitalized and the sentence ends with a punctuation mark. If it is not properly written, fix the sentence, print the type of error, and print the fixed sentence.




I was following the provided instructions for this class and keep getting an invalid syntax error for the fourth line of code. Was wondering if anyone knew why and could show me how to fix it or another way of writing this program.



import string

sentence = input("Enter a sentence ")

class acceptSentence():

punctuationcount = lambda a,b:len(list(filter(lambda c: c in b,a)))

numberofpunctuationcount = punctuationcount(sentence,string.punctuation)

for each in sentence:
if each.startswith(each.upper()):
print ("Starts with Capital letter ",each)

break

if (numberofpunctuations >=1):

print("Sentence Ends with punctuation")

else:
print("Error : there is no punctuion mark at end of setence")


obj = acceptSentence()
obj.calculate(sentence)









share|improve this question




















  • 1





    lamdba-c is an invalid syntax. Did you mean lambda c:?

    – Idlehands
    Nov 16 '18 at 15:52






  • 1





    Also the indentation is wrong, at least in this copy-pasted snippet

    – RunOrVeith
    Nov 16 '18 at 15:54











  • @Idlehands that's actually what it was originally I tried a few things to get it to work. it still shows the c as invalid syntax

    – Jacob
    Nov 16 '18 at 15:55











  • @RunOrVeith it is correct in the actual code i just didnt check it when it was copied

    – Jacob
    Nov 16 '18 at 15:56











  • If this is the actual snippet without any modification, besides the possible indentation issue, you haven't actually defined anything under class acceptSentence() so the interpreter is complaining. Seeing as how you refer to obj.calculate(sentence) though I'm assuming you had some definition you just omitted? Because nowhere is .calculate() method referenced.

    – Idlehands
    Nov 16 '18 at 15:59




















-1
















Write a program that prompts for the user to input a sentence. Then check this sentence to make sure the first word of the sentence is capitalized and the sentence ends with a punctuation mark. If it is not properly written, fix the sentence, print the type of error, and print the fixed sentence.




I was following the provided instructions for this class and keep getting an invalid syntax error for the fourth line of code. Was wondering if anyone knew why and could show me how to fix it or another way of writing this program.



import string

sentence = input("Enter a sentence ")

class acceptSentence():

punctuationcount = lambda a,b:len(list(filter(lambda c: c in b,a)))

numberofpunctuationcount = punctuationcount(sentence,string.punctuation)

for each in sentence:
if each.startswith(each.upper()):
print ("Starts with Capital letter ",each)

break

if (numberofpunctuations >=1):

print("Sentence Ends with punctuation")

else:
print("Error : there is no punctuion mark at end of setence")


obj = acceptSentence()
obj.calculate(sentence)









share|improve this question




















  • 1





    lamdba-c is an invalid syntax. Did you mean lambda c:?

    – Idlehands
    Nov 16 '18 at 15:52






  • 1





    Also the indentation is wrong, at least in this copy-pasted snippet

    – RunOrVeith
    Nov 16 '18 at 15:54











  • @Idlehands that's actually what it was originally I tried a few things to get it to work. it still shows the c as invalid syntax

    – Jacob
    Nov 16 '18 at 15:55











  • @RunOrVeith it is correct in the actual code i just didnt check it when it was copied

    – Jacob
    Nov 16 '18 at 15:56











  • If this is the actual snippet without any modification, besides the possible indentation issue, you haven't actually defined anything under class acceptSentence() so the interpreter is complaining. Seeing as how you refer to obj.calculate(sentence) though I'm assuming you had some definition you just omitted? Because nowhere is .calculate() method referenced.

    – Idlehands
    Nov 16 '18 at 15:59
















-1












-1








-1


1







Write a program that prompts for the user to input a sentence. Then check this sentence to make sure the first word of the sentence is capitalized and the sentence ends with a punctuation mark. If it is not properly written, fix the sentence, print the type of error, and print the fixed sentence.




I was following the provided instructions for this class and keep getting an invalid syntax error for the fourth line of code. Was wondering if anyone knew why and could show me how to fix it or another way of writing this program.



import string

sentence = input("Enter a sentence ")

class acceptSentence():

punctuationcount = lambda a,b:len(list(filter(lambda c: c in b,a)))

numberofpunctuationcount = punctuationcount(sentence,string.punctuation)

for each in sentence:
if each.startswith(each.upper()):
print ("Starts with Capital letter ",each)

break

if (numberofpunctuations >=1):

print("Sentence Ends with punctuation")

else:
print("Error : there is no punctuion mark at end of setence")


obj = acceptSentence()
obj.calculate(sentence)









share|improve this question

















Write a program that prompts for the user to input a sentence. Then check this sentence to make sure the first word of the sentence is capitalized and the sentence ends with a punctuation mark. If it is not properly written, fix the sentence, print the type of error, and print the fixed sentence.




I was following the provided instructions for this class and keep getting an invalid syntax error for the fourth line of code. Was wondering if anyone knew why and could show me how to fix it or another way of writing this program.



import string

sentence = input("Enter a sentence ")

class acceptSentence():

punctuationcount = lambda a,b:len(list(filter(lambda c: c in b,a)))

numberofpunctuationcount = punctuationcount(sentence,string.punctuation)

for each in sentence:
if each.startswith(each.upper()):
print ("Starts with Capital letter ",each)

break

if (numberofpunctuations >=1):

print("Sentence Ends with punctuation")

else:
print("Error : there is no punctuion mark at end of setence")


obj = acceptSentence()
obj.calculate(sentence)






python python-3.x






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 16:10









tobias_k

59.3k971110




59.3k971110










asked Nov 16 '18 at 15:48









JacobJacob

42




42








  • 1





    lamdba-c is an invalid syntax. Did you mean lambda c:?

    – Idlehands
    Nov 16 '18 at 15:52






  • 1





    Also the indentation is wrong, at least in this copy-pasted snippet

    – RunOrVeith
    Nov 16 '18 at 15:54











  • @Idlehands that's actually what it was originally I tried a few things to get it to work. it still shows the c as invalid syntax

    – Jacob
    Nov 16 '18 at 15:55











  • @RunOrVeith it is correct in the actual code i just didnt check it when it was copied

    – Jacob
    Nov 16 '18 at 15:56











  • If this is the actual snippet without any modification, besides the possible indentation issue, you haven't actually defined anything under class acceptSentence() so the interpreter is complaining. Seeing as how you refer to obj.calculate(sentence) though I'm assuming you had some definition you just omitted? Because nowhere is .calculate() method referenced.

    – Idlehands
    Nov 16 '18 at 15:59
















  • 1





    lamdba-c is an invalid syntax. Did you mean lambda c:?

    – Idlehands
    Nov 16 '18 at 15:52






  • 1





    Also the indentation is wrong, at least in this copy-pasted snippet

    – RunOrVeith
    Nov 16 '18 at 15:54











  • @Idlehands that's actually what it was originally I tried a few things to get it to work. it still shows the c as invalid syntax

    – Jacob
    Nov 16 '18 at 15:55











  • @RunOrVeith it is correct in the actual code i just didnt check it when it was copied

    – Jacob
    Nov 16 '18 at 15:56











  • If this is the actual snippet without any modification, besides the possible indentation issue, you haven't actually defined anything under class acceptSentence() so the interpreter is complaining. Seeing as how you refer to obj.calculate(sentence) though I'm assuming you had some definition you just omitted? Because nowhere is .calculate() method referenced.

    – Idlehands
    Nov 16 '18 at 15:59










1




1





lamdba-c is an invalid syntax. Did you mean lambda c:?

– Idlehands
Nov 16 '18 at 15:52





lamdba-c is an invalid syntax. Did you mean lambda c:?

– Idlehands
Nov 16 '18 at 15:52




1




1





Also the indentation is wrong, at least in this copy-pasted snippet

– RunOrVeith
Nov 16 '18 at 15:54





Also the indentation is wrong, at least in this copy-pasted snippet

– RunOrVeith
Nov 16 '18 at 15:54













@Idlehands that's actually what it was originally I tried a few things to get it to work. it still shows the c as invalid syntax

– Jacob
Nov 16 '18 at 15:55





@Idlehands that's actually what it was originally I tried a few things to get it to work. it still shows the c as invalid syntax

– Jacob
Nov 16 '18 at 15:55













@RunOrVeith it is correct in the actual code i just didnt check it when it was copied

– Jacob
Nov 16 '18 at 15:56





@RunOrVeith it is correct in the actual code i just didnt check it when it was copied

– Jacob
Nov 16 '18 at 15:56













If this is the actual snippet without any modification, besides the possible indentation issue, you haven't actually defined anything under class acceptSentence() so the interpreter is complaining. Seeing as how you refer to obj.calculate(sentence) though I'm assuming you had some definition you just omitted? Because nowhere is .calculate() method referenced.

– Idlehands
Nov 16 '18 at 15:59







If this is the actual snippet without any modification, besides the possible indentation issue, you haven't actually defined anything under class acceptSentence() so the interpreter is complaining. Seeing as how you refer to obj.calculate(sentence) though I'm assuming you had some definition you just omitted? Because nowhere is .calculate() method referenced.

– Idlehands
Nov 16 '18 at 15:59














3 Answers
3






active

oldest

votes


















0














Your code is not properly indented, which is what leads to an IndentationError when executing it. Your lambda filter also spits out a SyntaxError because of the incorrect spelling of "lambda". Your if-else statement is also misaligned, be careful how you indent your code.



Here's a simpler alternative to your program:



import string

sentence = input("Enter a sentence:")

first_word = sentence.split()[0] # .split() gives you a list of words in the sentence, 0 is the index of the first word;

capitalized_first_word = first_word.title() # .title() capitalizes a string;

# Check whether the first word is not equal to the capitalized word:
if first_word != capitalized_first_word:
print ("Sentence does not start with a capital letter.")
# Replace the first word in the sentence with the capitalized word:
sentence = sentence.replace(first_word, capitalized_first_word)

# Check if the sentence does not end with a punctuation mark, -1 is the index of the last character in the sentence:
if not sentence[-1] in string.punctuation:
print("Sentence does not end with punctuation.")
# Add punctuation to the end of the sentence:
sentence += '.'

# Print the sentence:
print(sentence)


Look into string indexing for more details.






share|improve this answer

































    0














    Just do:



    sentence = input("Enter a sentence ").lstrip()  # remove trailing whitespaces

    # check if first character is uppercase
    if not sentence[0].isupper():
    print("Sentence does not start with uppercase character")
    # correct the sentence
    sentence = sentence[0].upper() + sentence[1:]

    # check if last character is a punctuation
    # (feel free to add other punctuations)
    if sentence[-1] not in (['.']):
    print("Sentence does not end with punctuation character")
    # correct the sentence
    sentence += '.'

    #finally print the correct sentence
    print(sentence)





    share|improve this answer


























    • This is actually a much simple way of writing the program thank you! I don't know why the instructions I was provided were incorrect. looking at them again the expected output doesn't actually print the fixed sentence so thank you again.

      – Jacob
      Nov 16 '18 at 16:17



















    0














    Based on the description you may be overthinking the task: it speaks about a single sentence, and then you just have to make sure that the first letter is upper case and there is punctuation at the end:



    def sentence():
    text=input("Please type a sentence here: ")

    if text[0].isalpha() and not text[0].isupper(): # Begins with letter, but not uppercase?
    text=text[0].upper()+text[1:] # Make it uppercase then
    print("Sentences should start in uppercase");

    if text[-1] not in [".","!","?"]: # Does not end with punctuation?
    text+="." # Append a period then
    print("Sentences should end with punctuation mark")

    return text


    It can be both extended (like .strip()-ing whitespace, just add it to the input-line), or even shortened (the first if can be removed, since there is nothing wrong with calling .upper() on something what is uppercase already). However since the error has to be printed, the if has to stay in this particular case.






    share|improve this answer


























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53341199%2fwrite-a-program-that-prompts-for-the-user-to-input-a-sentence%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      Your code is not properly indented, which is what leads to an IndentationError when executing it. Your lambda filter also spits out a SyntaxError because of the incorrect spelling of "lambda". Your if-else statement is also misaligned, be careful how you indent your code.



      Here's a simpler alternative to your program:



      import string

      sentence = input("Enter a sentence:")

      first_word = sentence.split()[0] # .split() gives you a list of words in the sentence, 0 is the index of the first word;

      capitalized_first_word = first_word.title() # .title() capitalizes a string;

      # Check whether the first word is not equal to the capitalized word:
      if first_word != capitalized_first_word:
      print ("Sentence does not start with a capital letter.")
      # Replace the first word in the sentence with the capitalized word:
      sentence = sentence.replace(first_word, capitalized_first_word)

      # Check if the sentence does not end with a punctuation mark, -1 is the index of the last character in the sentence:
      if not sentence[-1] in string.punctuation:
      print("Sentence does not end with punctuation.")
      # Add punctuation to the end of the sentence:
      sentence += '.'

      # Print the sentence:
      print(sentence)


      Look into string indexing for more details.






      share|improve this answer






























        0














        Your code is not properly indented, which is what leads to an IndentationError when executing it. Your lambda filter also spits out a SyntaxError because of the incorrect spelling of "lambda". Your if-else statement is also misaligned, be careful how you indent your code.



        Here's a simpler alternative to your program:



        import string

        sentence = input("Enter a sentence:")

        first_word = sentence.split()[0] # .split() gives you a list of words in the sentence, 0 is the index of the first word;

        capitalized_first_word = first_word.title() # .title() capitalizes a string;

        # Check whether the first word is not equal to the capitalized word:
        if first_word != capitalized_first_word:
        print ("Sentence does not start with a capital letter.")
        # Replace the first word in the sentence with the capitalized word:
        sentence = sentence.replace(first_word, capitalized_first_word)

        # Check if the sentence does not end with a punctuation mark, -1 is the index of the last character in the sentence:
        if not sentence[-1] in string.punctuation:
        print("Sentence does not end with punctuation.")
        # Add punctuation to the end of the sentence:
        sentence += '.'

        # Print the sentence:
        print(sentence)


        Look into string indexing for more details.






        share|improve this answer




























          0












          0








          0







          Your code is not properly indented, which is what leads to an IndentationError when executing it. Your lambda filter also spits out a SyntaxError because of the incorrect spelling of "lambda". Your if-else statement is also misaligned, be careful how you indent your code.



          Here's a simpler alternative to your program:



          import string

          sentence = input("Enter a sentence:")

          first_word = sentence.split()[0] # .split() gives you a list of words in the sentence, 0 is the index of the first word;

          capitalized_first_word = first_word.title() # .title() capitalizes a string;

          # Check whether the first word is not equal to the capitalized word:
          if first_word != capitalized_first_word:
          print ("Sentence does not start with a capital letter.")
          # Replace the first word in the sentence with the capitalized word:
          sentence = sentence.replace(first_word, capitalized_first_word)

          # Check if the sentence does not end with a punctuation mark, -1 is the index of the last character in the sentence:
          if not sentence[-1] in string.punctuation:
          print("Sentence does not end with punctuation.")
          # Add punctuation to the end of the sentence:
          sentence += '.'

          # Print the sentence:
          print(sentence)


          Look into string indexing for more details.






          share|improve this answer















          Your code is not properly indented, which is what leads to an IndentationError when executing it. Your lambda filter also spits out a SyntaxError because of the incorrect spelling of "lambda". Your if-else statement is also misaligned, be careful how you indent your code.



          Here's a simpler alternative to your program:



          import string

          sentence = input("Enter a sentence:")

          first_word = sentence.split()[0] # .split() gives you a list of words in the sentence, 0 is the index of the first word;

          capitalized_first_word = first_word.title() # .title() capitalizes a string;

          # Check whether the first word is not equal to the capitalized word:
          if first_word != capitalized_first_word:
          print ("Sentence does not start with a capital letter.")
          # Replace the first word in the sentence with the capitalized word:
          sentence = sentence.replace(first_word, capitalized_first_word)

          # Check if the sentence does not end with a punctuation mark, -1 is the index of the last character in the sentence:
          if not sentence[-1] in string.punctuation:
          print("Sentence does not end with punctuation.")
          # Add punctuation to the end of the sentence:
          sentence += '.'

          # Print the sentence:
          print(sentence)


          Look into string indexing for more details.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 16 '18 at 16:24

























          answered Nov 16 '18 at 16:18









          Viktor PetrovViktor Petrov

          419




          419

























              0














              Just do:



              sentence = input("Enter a sentence ").lstrip()  # remove trailing whitespaces

              # check if first character is uppercase
              if not sentence[0].isupper():
              print("Sentence does not start with uppercase character")
              # correct the sentence
              sentence = sentence[0].upper() + sentence[1:]

              # check if last character is a punctuation
              # (feel free to add other punctuations)
              if sentence[-1] not in (['.']):
              print("Sentence does not end with punctuation character")
              # correct the sentence
              sentence += '.'

              #finally print the correct sentence
              print(sentence)





              share|improve this answer


























              • This is actually a much simple way of writing the program thank you! I don't know why the instructions I was provided were incorrect. looking at them again the expected output doesn't actually print the fixed sentence so thank you again.

                – Jacob
                Nov 16 '18 at 16:17
















              0














              Just do:



              sentence = input("Enter a sentence ").lstrip()  # remove trailing whitespaces

              # check if first character is uppercase
              if not sentence[0].isupper():
              print("Sentence does not start with uppercase character")
              # correct the sentence
              sentence = sentence[0].upper() + sentence[1:]

              # check if last character is a punctuation
              # (feel free to add other punctuations)
              if sentence[-1] not in (['.']):
              print("Sentence does not end with punctuation character")
              # correct the sentence
              sentence += '.'

              #finally print the correct sentence
              print(sentence)





              share|improve this answer


























              • This is actually a much simple way of writing the program thank you! I don't know why the instructions I was provided were incorrect. looking at them again the expected output doesn't actually print the fixed sentence so thank you again.

                – Jacob
                Nov 16 '18 at 16:17














              0












              0








              0







              Just do:



              sentence = input("Enter a sentence ").lstrip()  # remove trailing whitespaces

              # check if first character is uppercase
              if not sentence[0].isupper():
              print("Sentence does not start with uppercase character")
              # correct the sentence
              sentence = sentence[0].upper() + sentence[1:]

              # check if last character is a punctuation
              # (feel free to add other punctuations)
              if sentence[-1] not in (['.']):
              print("Sentence does not end with punctuation character")
              # correct the sentence
              sentence += '.'

              #finally print the correct sentence
              print(sentence)





              share|improve this answer















              Just do:



              sentence = input("Enter a sentence ").lstrip()  # remove trailing whitespaces

              # check if first character is uppercase
              if not sentence[0].isupper():
              print("Sentence does not start with uppercase character")
              # correct the sentence
              sentence = sentence[0].upper() + sentence[1:]

              # check if last character is a punctuation
              # (feel free to add other punctuations)
              if sentence[-1] not in (['.']):
              print("Sentence does not end with punctuation character")
              # correct the sentence
              sentence += '.'

              #finally print the correct sentence
              print(sentence)






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Nov 16 '18 at 16:24

























              answered Nov 16 '18 at 16:12









              Sembei NorimakiSembei Norimaki

              2,5801331




              2,5801331













              • This is actually a much simple way of writing the program thank you! I don't know why the instructions I was provided were incorrect. looking at them again the expected output doesn't actually print the fixed sentence so thank you again.

                – Jacob
                Nov 16 '18 at 16:17



















              • This is actually a much simple way of writing the program thank you! I don't know why the instructions I was provided were incorrect. looking at them again the expected output doesn't actually print the fixed sentence so thank you again.

                – Jacob
                Nov 16 '18 at 16:17

















              This is actually a much simple way of writing the program thank you! I don't know why the instructions I was provided were incorrect. looking at them again the expected output doesn't actually print the fixed sentence so thank you again.

              – Jacob
              Nov 16 '18 at 16:17





              This is actually a much simple way of writing the program thank you! I don't know why the instructions I was provided were incorrect. looking at them again the expected output doesn't actually print the fixed sentence so thank you again.

              – Jacob
              Nov 16 '18 at 16:17











              0














              Based on the description you may be overthinking the task: it speaks about a single sentence, and then you just have to make sure that the first letter is upper case and there is punctuation at the end:



              def sentence():
              text=input("Please type a sentence here: ")

              if text[0].isalpha() and not text[0].isupper(): # Begins with letter, but not uppercase?
              text=text[0].upper()+text[1:] # Make it uppercase then
              print("Sentences should start in uppercase");

              if text[-1] not in [".","!","?"]: # Does not end with punctuation?
              text+="." # Append a period then
              print("Sentences should end with punctuation mark")

              return text


              It can be both extended (like .strip()-ing whitespace, just add it to the input-line), or even shortened (the first if can be removed, since there is nothing wrong with calling .upper() on something what is uppercase already). However since the error has to be printed, the if has to stay in this particular case.






              share|improve this answer






























                0














                Based on the description you may be overthinking the task: it speaks about a single sentence, and then you just have to make sure that the first letter is upper case and there is punctuation at the end:



                def sentence():
                text=input("Please type a sentence here: ")

                if text[0].isalpha() and not text[0].isupper(): # Begins with letter, but not uppercase?
                text=text[0].upper()+text[1:] # Make it uppercase then
                print("Sentences should start in uppercase");

                if text[-1] not in [".","!","?"]: # Does not end with punctuation?
                text+="." # Append a period then
                print("Sentences should end with punctuation mark")

                return text


                It can be both extended (like .strip()-ing whitespace, just add it to the input-line), or even shortened (the first if can be removed, since there is nothing wrong with calling .upper() on something what is uppercase already). However since the error has to be printed, the if has to stay in this particular case.






                share|improve this answer




























                  0












                  0








                  0







                  Based on the description you may be overthinking the task: it speaks about a single sentence, and then you just have to make sure that the first letter is upper case and there is punctuation at the end:



                  def sentence():
                  text=input("Please type a sentence here: ")

                  if text[0].isalpha() and not text[0].isupper(): # Begins with letter, but not uppercase?
                  text=text[0].upper()+text[1:] # Make it uppercase then
                  print("Sentences should start in uppercase");

                  if text[-1] not in [".","!","?"]: # Does not end with punctuation?
                  text+="." # Append a period then
                  print("Sentences should end with punctuation mark")

                  return text


                  It can be both extended (like .strip()-ing whitespace, just add it to the input-line), or even shortened (the first if can be removed, since there is nothing wrong with calling .upper() on something what is uppercase already). However since the error has to be printed, the if has to stay in this particular case.






                  share|improve this answer















                  Based on the description you may be overthinking the task: it speaks about a single sentence, and then you just have to make sure that the first letter is upper case and there is punctuation at the end:



                  def sentence():
                  text=input("Please type a sentence here: ")

                  if text[0].isalpha() and not text[0].isupper(): # Begins with letter, but not uppercase?
                  text=text[0].upper()+text[1:] # Make it uppercase then
                  print("Sentences should start in uppercase");

                  if text[-1] not in [".","!","?"]: # Does not end with punctuation?
                  text+="." # Append a period then
                  print("Sentences should end with punctuation mark")

                  return text


                  It can be both extended (like .strip()-ing whitespace, just add it to the input-line), or even shortened (the first if can be removed, since there is nothing wrong with calling .upper() on something what is uppercase already). However since the error has to be printed, the if has to stay in this particular case.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 16 '18 at 16:47

























                  answered Nov 16 '18 at 16:16









                  tevemadartevemadar

                  4,6782827




                  4,6782827






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53341199%2fwrite-a-program-that-prompts-for-the-user-to-input-a-sentence%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Bressuire

                      Vorschmack

                      Quarantine