Python Forum
read words from the keyboard and store them
Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
read words from the keyboard and store them
#6
Here are some of the things that were incorrect:
from random import randrange
lista2 = []
a = True
# Set word to empty string
word = ''
i = 0

# made get_word a function as it needs to be called several times
def get_word():
    while word == '':
        # don't need i here
        # i=i+1
        # indentation was off on next line, added space after :,
        # added lower here rather than later, added spaces between operators
        b = input('give a word: ').lower()

        # following can be done better and needs to be redirected to run again:
        # if b == ('',' ',''):
        #     print('one word only.')
        word = b.split()
        if len(word) > 1:
            print('one word only.')
            # Set word back to '' so loop continues
            word = ''
        print('the word has been given')
    return word

# lista2.append(b)     
# b.lower()
# if b==lista2[i]:

# if b=='end':
#     break
# word==word+1
# if word<5:
#     print('very short number of words')
# print(b)
# print (word)
# print (lista2)
This will allow you to call get_word as many times as needed.
I didn't finish, but this will get you started
Reply


Messages In This Thread
RE: homework HELP ME! - by Larz60+ - Jan-13-2019, 05:48 PM
RE: homework HELP ME! - by geoe - Jan-13-2019, 06:07 PM
RE: homework HELP ME! - by Larz60+ - Jan-13-2019, 06:18 PM
RE: homework HELP ME! - by geoe - Jan-13-2019, 06:25 PM
RE: homework HELP ME! - by Larz60+ - Jan-13-2019, 06:46 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Can we store value in file if we open file in read mode? prasanthbab1234 3 2,655 Sep-26-2020, 12:10 PM
Last Post: ibreeden
  Read data from a CSV file in S3 bucket and store it in a dictionary in python Rupini 3 7,136 May-15-2020, 04:57 PM
Last Post: snippsat
  Read keyboard until keypress ytav 1 2,291 Jun-09-2018, 01:14 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020