- Strength to Increase Rep
- +0
- Strength to Decrease Rep
- -0
- Upvotes Received
- 2
- Posts with Upvotes
- 1
- Upvoting Members
- 2
- Downvotes Received
- 0
- Posts with Downvotes
- 0
- Downvoting Members
- 0
3 Posted Topics
[QUOTE=bumsfeld;260289]If you have simple English word like: [CODE]str1 = 'supercalifragilisticexpialidocious'[/CODE] How would you form string that has every second letter in capital (upper case).[/QUOTE] I do not know if it is appropriate to post a solution here. But I would like to have feedback to see if my solution can …
Here is another solution: [CODE]numbers = '123456789' i = 1 j = 0 for num in numbers: x = (int(numbers[0:i])) y = (int(numbers[j])) tot = (int(numbers[0:i])*8+(int(numbers[j]))) i += 1 j += 1 print("%d*8+%d=%d" % (x, y, tot))[/CODE] 1*8+1=9 12*8+2=98 123*8+3=987 1234*8+4=9876 12345*8+5=98765 123456*8+6=987654 1234567*8+7=9876543 12345678*8+8=98765432 123456789*8+9=987654321
Here is another solution using only "strings, lists, and appropriate operators/methods". [CODE]def convert_mnth(date_string): months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"] month = months[int(date_string[-10:-8])-1] day = date_string[-8:-5] year = date_string[-5:] print("%s%s%s" %(month,day,year))[/CODE] _____________________________________________________ >>>convert_mnth('12/23/2010') Dec/23/2010 >>> convert_mnth('1/23/2010') Jan/23/2010
The End.
Legnoduro