Reputation: 1
So I am trying to get the following on Python 3:
Please enter a word or phrase: Computer Science
e
ce
nce
ence
ience
cience
Science
Science
r Science
er Science
ter Science
uter Science
puter Science
mputer Science
omputer Science
Computer Science
So we had to define this function called word_processor
that takes no parameters. So far I have this down for it:
def main():
word_processor()
def word_processor():
value = input("Please enter a word or phrase: ")
word = len(value)
for i in range(-1, word + 1):
print(' ' * (word - i) * i)
main()
Whenever I run this code, it tells me to put the phrase and from there, it does nothing. I have no idea what I am doing and I need some help. If someone could help with this, I would greatly appreciate it so much!
Upvotes: 0
Views: 242
Reputation: 387677
It does something, it even prints something; but that what it prints is just whitespace:
print(' ' * (word - i) * i)
This just prints (word - i) * i
times a space character, so of course you don’t see anything.
In order to produce the output you desire, you would need to do something like this:
for i in range(1, len(value) + 1):
print(value[-i:])
Upvotes: 1