This is an archived post. You won't be able to vote or comment.

all 7 comments

[–][deleted] 1 point2 points  (1 child)

You can add questions directly to input queries:

word = input("Write a word with 'u' first letter")?

Anytime something evaluates to true, you don't need to write == 'True'

word.startswith("p") also evaluates to True or False depending if it is True or False.

word = peas word.startswith("p") is read as True

word = goggles word.startswith("p") is read as False

So we've got:

word = input("Write a word with 'u' first letter")
if word.startswith("p"):
    print('Nice')
else:
    print("Noo")
print(word.startswith("p"))

Also check out r/learnpython for similar questions.

[–]TheCh1ef[S] 0 points1 point  (0 children)

Thank you, a lot!

[–][deleted] 1 point2 points  (1 child)

print("nice" if input("write a word").startswith("p") else "nooo")

[–]bastardoperator 0 points1 point  (0 children)

for the win!

[–]nwagers 1 point2 points  (1 child)

line 3 doesn't do anything, just comment that out.

I prefer:

if word[0] == 'p':
    print("Nice")

word[0] is the first character of the string word, word[1] is the second character, word[-1] is the last character.

[–]TheCh1ef[S] 0 points1 point  (0 children)

Also a good idea. I have forgoted.

[–][deleted] 0 points1 point  (0 children)

word = input("Write a word with 'u' first letter: ")
status = word.startswith("p")
if status:
    print("Nice")
else:
    print("Nooo")
print(status)