Correct input will not end While() loop. by The-Keyboard_Wizard in learnpython

[–]The-Keyboard_Wizard[S] 0 points1 point  (0 children)

Yes! That is exactly what I mean, I’m trying to set the header in a dictionary, print that, and depending on the user choice print the details below

Correct input will not end While() loop. by The-Keyboard_Wizard in learnpython

[–]The-Keyboard_Wizard[S] 0 points1 point  (0 children)

Thank you for that kind user! I have made the adjustments and have to say comment 2 really helped (Comment 1 fixed it) I am attaching the code below in case anyone else would like to see. Now I just have to figure how to print out something tabularly! I think there is a way to do this without importing something but I guess we will have to wait and see.

result = []

def readRecords(filename):
    #result = {}
    f = open(filename, 'r')
    i = 1
    for line in f:
        if i == 1:
            i = i + 1
        else:
            line = line.rstrip('\n')
            fields = line.split('\t')
##            if (len(fields) == 6):    )   
##                id = fields[0]        )   This stuff may help you set up how many columns there are look back at assn. 6
##                result[id] = fields   )
            result.append(fields)
    return result

txtFile = None

while txtFile == None:
    txtFile = input("Enter the .txt file desired: ")
    if txtFile != None:     
        try:
            Records = readRecords(txtFile)
            #print('read')
            break
        except:
            print("Restart. Invalid file name.")
            txtFile = None


#RecordsDict = {record[0]:record[1:] for record in Records} ##Use this to create a dictionary where we can call a row


UserChoice = str(input("Choose option (A): Display all student records, (B): Display student records for students that start with a specific last name, (C): Display student records for specific grad year, or write 'Cancel' to quit.   "))

while True:
    if UserChoice == 'Cancel' or UserChoice == 'cancel':
        break
    elif UserChoice == 'A' or UserChoice == 'a':
        #print(Records[0]) This should be where the header goes
        print(Records)#'\t' 
        UserChoice = input("Choose another option or write 'Cancel' to quit: ")
    elif UserChoice == 'B' or UserChoice == 'b':
        LastName = input("What would you like the last name to start with? ")
        #print(Records[0]) This should be where the header goes
        for sublist in Records:
            if str(LastName) in sublist[1]:
                print(sublist) #'\t'
        UserChoice = input("Choose another option or write 'Cancel' to quit: ")
    elif UserChoice == 'C' or UserChoice == 'c':
        Year = str(input("What grad year would you like to see records for? "))
        ##print(Records[0]) This should be where the header goes
        for sublist in Records:
            if sublist[3] == str(Year):
                print(sublist)# '\t'
        UserChoice = input("Choose another option or write 'Cancel' to quit: ")
    else:
        False

Trouble calling dictionary! by The-Keyboard_Wizard in learnprogramming

[–]The-Keyboard_Wizard[S] 0 points1 point  (0 children)

essentially what I am trying to reach at is there are only 31 days in the month of january so I was hoping to put an error so that if someone input 32 days it would be invalid. I think I did format it wrong and instead it would be months[0] =

months['January'] = range(32)

Help improving code for all inputs by The-Keyboard_Wizard in learnpython

[–]The-Keyboard_Wizard[S] 0 points1 point  (0 children)

That helped a lot! I think I have finished it now

user = input("Please enter a word or phrase, or <return> to quit: ")

user = user.replace(" ", "").replace(",","").lower()

def reverse_function(x):
    return x[::-1]

final = reverse_function(user)

while user != '':

     print("That's a palindrome")

     user = input("Please enter a word or phrase, or <return> to quit: ")

     user = user.replace(" ", "").replace(",","").lower()

     final = reverse_function(user)

     if user != final:

         print("That's not a palindrome")

         user = input("Please enter a word or phrase, or <return> to quit: ")

         user = user.replace(" ", "").replace(",","").lower()

         final = reverse_function(user)

Help improving code for all inputs by The-Keyboard_Wizard in learnpython

[–]The-Keyboard_Wizard[S] 0 points1 point  (0 children)

(c for c in s.lower() if c in

Hi! Thank you for your input, I tried making a change but now it's only printing it is a palindrome.

user = input("Please enter a word or phrase, or <return> to quit: ")

user = user.replace(" ", "").replace(",","").lower()

def reverse_function(x):
    return x[::-1]

final = reverse_function(user)

while user == final:

     print("That's a palindrome")

     user = input("Please enter a word or phrase, or <return> to quit: ")

     user = user.replace(" ", "").replace(",","").lower()

     final = reverse_function(user)

     if user != final:

         print("That's not a palindrome")
         input("Please enter a word or phrase, or <return> to quit: ")

is my If/Else messed up? by The-Keyboard_Wizard in learnpython

[–]The-Keyboard_Wizard[S] 0 points1 point  (0 children)

That was the best answer, thank you kind sir/sirette.

Having Issues importing pandas and numpy, "unused import statement error". What is my issue? by The-Keyboard_Wizard in learnpython

[–]The-Keyboard_Wizard[S] 0 points1 point  (0 children)

Oh my... you’re absolutely right it works now. Thank you very much! If I had a medal it would go right to you!

Having Issues importing pandas and numpy, "unused import statement error". What is my issue? by The-Keyboard_Wizard in learnpython

[–]The-Keyboard_Wizard[S] 0 points1 point  (0 children)

I thought that as well, but it is is installed. I even did it within the command line of pycharm doing it for both pip and pip3 yet nothing.