Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with code
#3
Hi, thanks for the reply, I apologize as it does not need surrounding characters but the following two. Example, house would generate USE for the threeup. I found your other tips to be successful and thank you, however for line 5, it does not print the middle character but it prints the first character (when inputting "dog", it states that the middle character is "d".) Thanks for any help you can offer, below is the new code, I apologize in advance if I do not reply soon, as I have to leave my PC for a couple hours while I leave in around 10 minutes. Thanks in advance.

a = raw_input("Enter a Phrase: ")
numb = len(a)
mid = int(len(a) // 2)
if numb == 3:
    mid = (len(a) // 2 - 1)
    threeup = a[mid - 1] + a[mid] + a[mid + 1]
    threelow = a[mid - 1] + a[mid] + a[mid + 1]
if numb == 4:
    mid = int(len(a) // 2)
    
else:
    threeup = a[mid] + a[mid + 1] + a[mid + 2]
    threelow = a[mid] + a[mid + 1] + a[mid + 2]

    print "There are "  + str(numb) + " characters in this phrase"
    print "" + str(a[mid]) + " is the middle character"
    print threelow.lower()
    print threeup.upper()
Reply


Messages In This Thread
Help with code - by aspeniii - Nov-29-2018, 06:32 PM
RE: Help with code - by ichabod801 - Nov-29-2018, 06:53 PM
RE: Help with code - by aspeniii - Nov-29-2018, 07:18 PM
RE: Help with code - by ichabod801 - Nov-29-2018, 08:52 PM

Forum Jump:

User Panel Messages

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