Re: Implement C's Switch in Python 3

2019-02-02 Thread Sayth Renshaw
On Sunday, 3 February 2019 14:31:14 UTC+11, Avi Gross wrote: > Yes, you caught the usual flaw in the often irregular English language. > > The 11th, 12th and 13th do all begin with 1 so there is a simple fix in the > function version by checking if day//10 is 1. > > Revised example: > > """ Use

RE: Implement C's Switch in Python 3

2019-02-02 Thread Avi Gross
Yes, you caught the usual flaw in the often irregular English language. The 11th, 12th and 13th do all begin with 1 so there is a simple fix in the function version by checking if day//10 is 1. Revised example: """ Use last digit to determine suffix handling teens well """ def nthSuffix(day):

Re: Implement C's Switch in Python 3

2019-02-02 Thread Igor Korot
Hi, On Sat, Feb 2, 2019 at 8:54 PM Avi Gross wrote: > > I may be missing something, but the focus seems to be only on the rightmost > digit. You can get that with > > > str(day)[-1] > or with > day % 10 > > Problem: print 1..31 using suffixes such as 1st, 2nd, 3rd, 4th ... > > So y

Re: Implement C's Switch in Python 3

2019-02-02 Thread MRAB
On 2019-02-03 02:51, Avi Gross wrote: I may be missing something, but the focus seems to be only on the rightmost digit. You can get that with I had the same thought, but came across a problem. "11st", "12nd", "13rd"? [snip] Output: for day in range(1, 32): print( nthSuffix(day))

RE: Implement C's Switch in Python 3

2019-02-02 Thread Avi Gross
I may be missing something, but the focus seems to be only on the rightmost digit. You can get that with str(day)[-1] or with day % 10 Problem: print 1..31 using suffixes such as 1st, 2nd, 3rd, 4th ... So your dictionary needs entries for "1" or 1 and "2" or "2" and of course 3

Re: Implement C's Switch in Python 3

2019-02-02 Thread Skip Montanaro
Cameron wrote: > Skip has commented on lists being unhashable. We can elaborate on that > if you like. > > However, even if you went to tuples (which would let you construct the > dict you lay out above), there is another problem. > > You're looking up "x" in the dict. But the keys of the dict are

Re: Implement C's Switch in Python 3

2019-02-02 Thread Sayth Renshaw
> >I am trying to convert a switch statement from C into Python. (why? > >practising). > > > >This is the C code. > > > >printf("Dated this %d", day); > > switch (day) { > >case 1: case 21: case 31: > >printf("st"); break; > >case 2: case 22: > >printf("nd"); break; > >

Re: Implement C's Switch in Python 3

2019-02-02 Thread Cameron Simpson
On 02Feb2019 16:47, Sayth Renshaw wrote: I am trying to convert a switch statement from C into Python. (why? practising). This is the C code. printf("Dated this %d", day); switch (day) { case 1: case 21: case 31: printf("st"); break; case 2: case 22: printf("nd"); break;

Re: Implement C's Switch in Python 3

2019-02-02 Thread Chris Angelico
On Sun, Feb 3, 2019 at 11:51 AM Sayth Renshaw wrote: > > Hi > > I am trying to convert a switch statement from C into Python. (why? > practising). > > This is the C code. > > printf("Dated this %d", day); > switch (day) { > case 1: case 21: case 31: > printf("st"); break; > case

Re: Implement C's Switch in Python 3

2019-02-02 Thread Skip Montanaro
> > I have an unhashable type list. > Try replacing the list with a tuple. Also, read up on immutable v mutable types and dictionary keys for a bit of background on why a list won't work. Skip > -- https://mail.python.org/mailman/listinfo/python-list

Implement C's Switch in Python 3

2019-02-02 Thread Sayth Renshaw
Hi I am trying to convert a switch statement from C into Python. (why? practising). This is the C code. printf("Dated this %d", day); switch (day) { case 1: case 21: case 31: printf("st"); break; case 2: case 22: printf("nd"); break; case 3: case 23: printf

Re: cant use def command

2019-02-02 Thread John Doe
On 2019-02-01, mb1541def 0 <12345678mb1541...@gmail.com> wrote: > > Hello, > I need help on the def command. > > My script: > > Import os > Test > > def Test(): > print(“test”) > os.system(“pause”) > > someone please help,it gives me an error in python 3. > I did everything right. > On 2019-02-01,

Re: cant use def command

2019-02-02 Thread MRAB
On 2019-02-01 15:49, mb1541def 0 wrote: Hello, I need help on the def command. My script: Import os Test def Test(): print(“test”) os.system(“pause”) someone please help,it gives me an error in python 3. I did everything right. --mb1541def You didn't say what the error was, so I'll just co

Re: cant use def command

2019-02-02 Thread Terry Reedy
On 2/1/2019 10:49 AM, mb1541def 0 wrote: Hello, I need help on the def command. My script: Import os Test def Test(): print(“test”) os.system(“pause”) someone please help,it gives me an error in python 3. The python authors already did by providing you with a traceback that explains what

cant use def command

2019-02-02 Thread mb1541def 0
Hello, I need help on the def command. My script: Import os Test def Test(): print(“test”) os.system(“pause”) someone please help,it gives me an error in python 3. I did everything right. --mb1541def -- https://mail.python.org/mailman/listinfo/python-list

Re: OT - need help with PHP

2019-02-02 Thread Bob Gailer
Thank you. I will get back to you on that shortly. Bob -- https://mail.python.org/mailman/listinfo/python-list