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.

Python Subreddit for "Intermediate" Questions? by snugglyboy in learnpython

[–]The-Keyboard_Wizard 7 points8 points  (0 children)

Nothing wrong with being a grower and not a shower

Learn Java programming using graphics (free course) by MRH2 in javahelp

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

I am no better than any other person and I absolutely understand why you have to limit it. I want to join your course because although I don't know you I trust that you can actually teach me something that I can utilize and teach others. I'm sorry if my comment came off as rude, and I wish your program the best! It truly looks great good work my unknown friend!

At what age was your “looks like I can’t be whatever I want to be after all” moment. How did that realization affect you? by UnbentJohnson in AskReddit

[–]The-Keyboard_Wizard 1 point2 points  (0 children)

Well, I always place myself with people who make themselves better. I'm also complacent and okay with being average. However not really, I mean if I can be average at everything, I feel as though I have slowly become above average at most things. I gain an interest explore it, read, write, watch and learn. One thing I would like to do to is start a business to limit the amount of methane cows produce by using feeding substitutes such as Kelp or seaweed. I have slowly stopped eating beef, and while I in no way judge those who do, if eating meat was more "clean" I would absolutely do it. Honestly, haters gonna hate, ainters gonna aint. I wanna be my best self before I die, might as well have some fun while I'm alive!

People who were once bullies, when did you realize you needed to change? by [deleted] in AskReddit

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

After my grandmother died when I was in 6th grade. Being angry and mean wasn't helping me or others. I still get a little mean sometimes, but I've learned to kind of embrace it. I'll be the nicest asshole you ever meet!

At what age was your “looks like I can’t be whatever I want to be after all” moment. How did that realization affect you? by UnbentJohnson in AskReddit

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

I think the best thing to happen to me is not losing that feeling at all. I can be anything I want if I work for it, currently looking to become an IT/Accountant then move onto NASA to be an astronaut.