Post: Python Task Help Continued
07-20-2016, 04:17 PM #1
Ali
Can’t trickshot me!
(adsbygoogle = window.adsbygoogle || []).push({}); After my previous help thanks to john and toxic it's given me pieces of code i can just c & p to mine... right now my code is...

    
import re
while True:
* * sentence = input("Enter a sentence: ")
* * if not re.match("^[a-zA-Z ]*$", sentence):
* * * * print("Error! Only letters a-z allowed!")
* * else:
* * * * sentence.split()
* * * * break
splitsentence = sentence.split()
word = input("Enter a word from your sentence.")
if word in splitsentence:
* * print("The word:",word, "is located on word number(s):", splitsentence.index(word))
else:
* * print("Error! Word not found in your sentence.")


**** represent indentation

When it outputs the position of the first word.... It outputs it as if its a list, so it will say its in word position 0 for example;

You must login or register to view this content.


I'm just wondering if its possible to display 1 instead of 0 for the first word... If so show me how to implement it into my code to make it work...

There'll be another thread which ima make at some point regarding this task so yeah.... Be awake and be ready to help c:
07-20-2016, 04:33 PM #2
Originally posted by Ali View Post
After my previous help thanks to john and toxic it's given me pieces of code i can just c & p to mine... right now my code is...

    
import re
while True:
* * sentence = input("Enter a sentence: ")
* * if not re.match("^[a-zA-Z ]*$", sentence):
* * * * print("Error! Only letters a-z allowed!")
* * else:
* * * * sentence.split()
* * * * break
splitsentence = sentence.split()
word = input("Enter a word from your sentence.")
if word in splitsentence:
* * print("The word:",word, "is located on word number(s):", splitsentence.index(word))
else:
* * print("Error! Word not found in your sentence.")


**** represent indentation

When it outputs the position of the first word.... It outputs it as if its a list, so it will say its in word position 0 for example;

You must login or register to view this content.


I'm just wondering if its possible to display 1 instead of 0 for the first word... If so show me how to implement it into my code to make it work...

There'll be another thread which ima make at some point regarding this task so yeah.... Be awake and be ready to help c:


Why would you want it to print out 1 rather than 0? That's wrong.

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo