Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
If/else problems
#41
Yes you could go with
.upper()
.lower()
and the best one to suit your need is:
.capitalize()

print('WiZaRd'.lower())
print('WiZaRd'.upper())
print('WiZaRd'.captialize())
Output:
wizard WIZARD Wizard
When my code doesn't work I don't know why **think** and when my code works I don't know why **think**
Reply
#42
Hmm where am I supposed to put it? in the input line? input.capitalise?
Reply
#43
def c():
    found = False
    jobs = input("Enter the job title: ")
    #right here!
    jobs = jobs.capitalize()
    for b in employees:
        if jobs == b[2]:
             
            ## what with the len(i) in these if-statement
            if len(b)==5:
                print('%-30s' % (b[4]+ ','+' '+b[3]))
                found = True
            if len(b)==6:
                print('%-30s' % (b[5]+','+' '+b[3]+' '+b[4]))
                found = True
            if len(b)==7: 
                print('%-30s' % (b[6]+','+' '+b[3]+' '+b[4]+' '+b[5]))
                found = True
    if found == False:
        print("There is no such job")
When my code doesn't work I don't know why **think** and when my code works I don't know why **think**
Reply
#44
To put all the chances on your side, you should write:
if jobs == b[2].capitalize():
Just in case that the input file contains job names written in lower cases or upper cases.
Reply
#45
Yay thanks! Fully working exercise now. Satisfying.

I see. What could go wrong with jobs = jobs.capitalize()?

Oooh got it.
Reply
#46
In fact, you need both:
First jobs = jobs.capitalize()
Second, when you do the comparison, make sure that you compare with something that is capitalized as well, hence if jobs == b[2].capitalize():
Reply
#47
You guys willing to help with second part of the assignment?
Reply
#48
Yes, it a good standard practice. But the data he provided didn't have that problem so it wasn't necessary to do so.

Yes, I on board! Kind of annoyed that we did not manage to get the previous one in on time...
When my code doesn't work I don't know why **think** and when my code works I don't know why **think**
Reply
#49
I made a new thread for the second part. I think that's best. It's called word search grid.
Reply


Forum Jump:

User Panel Messages

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