Re: [Tutor] How to print lines within two timestamp

2018-10-26 Thread Peter Otten
Alan Gauld via Tutor wrote:

> On 26/10/2018 18:45, Alan Gauld via Tutor wrote:
> 
>> It woiyukld
> 
> No idea what happened there. Should be "would" of course!

Of coiyukrse! Nobody thoiyukght otherwiiyske :)

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help

2018-10-26 Thread Alan Gauld via Tutor
On 26/10/2018 18:20, Adam Eyring wrote:

> beef = (beefmeals * 15.95)

Note that the parens here are completely redundant.
They don't break anything but neither do they
contribute anything.

WE already have LISP(*) for those who love parens,
no need for (so many of) them in Python

(*)Lots of Irrelevant Silly Parentheses :

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to print lines within two timestamp

2018-10-26 Thread Alan Gauld via Tutor
On 26/10/2018 18:45, Alan Gauld via Tutor wrote:

> It woiyukld 

No idea what happened there. Should be "would" of course!

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help

2018-10-26 Thread Adam Eyring
On Fri, Oct 26, 2018 at 3:03 PM Bob Gailer  wrote:

> On Oct 26, 2018 1:20 PM, "Adam Eyring"  wrote:
> >
> > Try this cleaned up version with colons in the right places, dollar
> signs removed, and other corrections:
>
> Does it do what you want?
>
> > beefmeals=int(input("Enter number of beef meals: "))
> > shitmeals=int(input("Enter number of vegan meals: "))
> > party = beefmeals + shitmeals
> > print("Total meals", party)
> > a = 0
> > b = 0
> > c = 0
>
> There is no need for three variables here. You only need one to represent
> room cost. If you make that change then you will also not need to
> initialize the room cost variable. Makes the code simpler to maintain and
> read and understand.
>
> > if party <= 50:
> >
> > a=75
> > print("Room cost $75")
>
> If you use one variable for room cost then you can use just one print just
> above the room tax line.
>
> > elif party <= 150:
> >
> > b=150
> > print("Room cost $150")
> > else:
> > c=250
> > print("Room cost $250")
> > roomtax = party * 0.065
> > print("Room tx", roomtax)
> > print("Beef Meals", beefmeals)
> > beef = (beefmeals * 15.95)
> > print("Beef cost", beef)
> > print("Vegan Meals", shitmeals)
> > shit = (shitmeals * 10.95)
> > print("Vegan cost", shit)
> > cost=(beef + shit)
> > grat= cost * 0.18
> > print("Gratuity", grat)
> > GT = print("Grand total", grat + beef + shit + a + b + c)
>
> The print function always returns None. Therefore the effect of this
> statement is to assign None to GT. Also note that you don't use GT later on.
>

You're right - GT is not needed. The print does work with or without "GT
=" in Python 3.6.5, though.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help

2018-10-26 Thread Adam Eyring
Try this cleaned up version with colons in the right places, dollar signs
removed, and other corrections:

beefmeals=int(input("Enter number of beef meals: "))
shitmeals=int(input("Enter number of vegan meals: "))
party = beefmeals + shitmeals
print("Total meals", party)
a = 0
b = 0
c = 0
if party <= 50:
a=75
print("Room cost $75")
elif party <= 150:
b=150
print("Room cost $150")
else:
c=250
print("Room cost $250")
roomtax = party * 0.065
print("Room tx", roomtax)
print("Beef Meals", beefmeals)
beef = (beefmeals * 15.95)
print("Beef cost", beef)
print("Vegan Meals", shitmeals)
shit = (shitmeals * 10.95)
print("Vegan cost", shit)
cost=(beef + shit)
grat= cost * 0.18
print("Gratuity", grat)
GT = print("Grand total", grat + beef + shit + a + b + c)

On Fri, Oct 26, 2018 at 7:28 AM Bob Gailer  wrote:

> On Oct 26, 2018 6:11 AM, "Ben Placella" 
> wrote:
> >
> > I need to write code that runs a  cost calculating program with many
> > different variables and I honestly don't understand it
>
> Could you be more specific? What exactly don't you understand, or even
> better what do you understand?
>
> my code is:
>
> How could you have written so much code without understanding it?
>
> > beefmeals=int(input("Enter number of beef meals: "))
> > shitmeals=int(input("Enter number of vegan meals: "))
> > party=beefmeals+shitmeals
> > print(party)
> > if party<=50
>
> Something is missing from that last statement. Can you tell what it is? Do
> you know how to find out? Hint use help.
>
> Hint 2 it is also missing from the elif and else statements.
>
> > a=75
> > print("Room cost $75")
> > elif party <=150
> > b=150
> > print("Room cost $150")
> > else
> > c=250
> > print("Room cost $250")
> > roomtax=party*0.065
> > print(roomtax)
> > print("Beef Meals", beefmeals)
> > $beef=(beefmeals*15.95)
> > print($beef)
> > print("Beef cost", $$beef)
> > print("Vegan Meals", shitmeals)
> > $shit=(shitmeals*10.95)
> > print($shit)
> > cost=($beef+$shit)
> > grat=cost*0.18)
> > print(grat)
> > GT=(grat+$beef+$shit+(a,b,c))
>
> There is a convention in Python that and all uppercase name is a constant.
> This is not a requirement.
>
> > print(GT)
> >
> > This is what the output is supposed to be:
>
> I don't see any output here. Alan''s responses may help you figure that
> out.
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help

2018-10-26 Thread Bob Gailer
On Oct 26, 2018 1:20 PM, "Adam Eyring"  wrote:
>
> Try this cleaned up version with colons in the right places, dollar signs
removed, and other corrections:

Does it do what you want?

> beefmeals=int(input("Enter number of beef meals: "))
> shitmeals=int(input("Enter number of vegan meals: "))
> party = beefmeals + shitmeals
> print("Total meals", party)
> a = 0
> b = 0
> c = 0

There is no need for three variables here. You only need one to represent
room cost. If you make that change then you will also not need to
initialize the room cost variable. Makes the code simpler to maintain and
read and understand.

> if party <= 50:
>
> a=75
> print("Room cost $75")

If you use one variable for room cost then you can use just one print just
above the room tax line.

> elif party <= 150:
>
> b=150
> print("Room cost $150")
> else:
> c=250
> print("Room cost $250")
> roomtax = party * 0.065
> print("Room tx", roomtax)
> print("Beef Meals", beefmeals)
> beef = (beefmeals * 15.95)
> print("Beef cost", beef)
> print("Vegan Meals", shitmeals)
> shit = (shitmeals * 10.95)
> print("Vegan cost", shit)
> cost=(beef + shit)
> grat= cost * 0.18
> print("Gratuity", grat)
> GT = print("Grand total", grat + beef + shit + a + b + c)

The print function always returns None. Therefore the effect of this
statement is to assign None to GT. Also note that you don't use GT later on.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to print lines within two timestamp

2018-10-26 Thread Alan Gauld via Tutor
On 26/10/2018 12:33, Asad wrote:
> Hi ,
> 
> Yes i have the code :

It woiyukld help us to help you if you provided some clues as to what it
was doing.
A good start would be some comments - especially around the regexes.
Don't make us parse them without some idea of what you are expecting.
Also moremeaningful variable names than h,j,k etc

> import re
> import datetime
> from datetime import timedelta

You don't appear to use timedelta?

> Header = "*"
> 
> f3 = open ( r"D:\QI\logA.txt", 'r' )
> string = f3.read ()
> regex = re.compile ( "\n" )
> st = regex.sub ( " ", string )

I suspect regular string methods would be simpler here.

> st1 = st.split ( " " )
> 
> if re.search ('ERR-1:', st ):
> x = re.findall ( "(\w{3})\s+([0-9]{2})\s+(\d+):(\d+):(\d+)\s+(\d+)", st )
> j = x[0][0] + " "+ x[0][1]+" " + x[0][2] +":"+ x[0][3]+":" +
> x[0][4]+" " + x[0][5]
> h = x[1][0] + " "+ x[1][1]+" "+ x[1][2] +":" + x[1][3] +":"+
> x[1][4] +" "+ x[1][5]

I'm not sure what exactly this is doing, but I suspect
datetime.strftime might do it better.


> y = datetime.datetime.strptime ( j, '%b %d %H:%M:%S %Y' )
> print y
> k = datetime.datetime.strptime ( h, '%b %d %H:%M:%S %Y' )
> print k
> 
> f4 = open ( r"D:\QI\logC11.txt", 'r' )
> 
> string1 = f4.read ()
> reg = re.compile ( "\n" )
> newst = reg.sub ( " ", string1 )
> newst1 = newst.split ( " " )
> 
> if re.search ( "ERR-2", newst ):
> a = re.findall ( "\d\d/\d\d/\d\d\s[012][0-9]:[0-5][0-9]:[0-5][0-9]", 
> newst )
> for i in range ( len ( a ) ):

Would this not be simpler as

  for result in a:

and use result instead of a[i]

> newtime = datetime.datetime.strptime ( a[i], '%m/%d/%y %H:%M:%S' )
> if newtime > y and newtime < k:

You should be able to write this as

if y < newtime < k:


>print "Install patch1"
> 
> if re.search ( "ERR-3", newst ):
> a = re.findall ( "\d\d/\d\d/\d\d\s[012][0-9]:[0-5][0-9]:[0-5][0-9]", 
> newst )
> for i in range ( len ( a ) ):
> newtime = datetime.datetime.strptime ( a[i], '%m/%d/%y %H:%M:%S' )
> if newtime > y and newtime < k:
> print newtime, y, k
> print "Install patch2"
> 
> ==
> 
> output i get :


Can you show us the full output? It should start with your header line?

> *Install patch1   - wrong solution
> 2018-10-22 10:21:23 2018-10-22 10:21:15 2018-10-22 10:21:25
> Install patch2   - correct solution *
> 
> 
> *It should have only searched between timestamps **2018-10-22 10:21:15
> 2018-10-22 10:21:25*

Going by the above output that's exactly what it did?
And it found 2018-10-22 10:21:23

I'm not clear what you expected.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] How to print lines within two timestamp

2018-10-26 Thread Asad
Hi ,

Yes i have the code :

import re
import datetime
from datetime import timedelta

Header = "*"

f3 = open ( r"D:\QI\logA.txt", 'r' )
string = f3.read ()
regex = re.compile ( "\n" )
st = regex.sub ( " ", string )
st1 = st.split ( " " )

if re.search ('ERR-1:', st ):
x = re.findall ( "(\w{3})\s+([0-9]{2})\s+(\d+):(\d+):(\d+)\s+(\d+)", st )
j = x[0][0] + " "+ x[0][1]+" " + x[0][2] +":"+ x[0][3]+":" +
x[0][4]+" " + x[0][5]
h = x[1][0] + " "+ x[1][1]+" "+ x[1][2] +":" + x[1][3] +":"+
x[1][4] +" "+ x[1][5]
y = datetime.datetime.strptime ( j, '%b %d %H:%M:%S %Y' )
print y
k = datetime.datetime.strptime ( h, '%b %d %H:%M:%S %Y' )
print k

f4 = open ( r"D:\QI\logC11.txt", 'r' )

string1 = f4.read ()
reg = re.compile ( "\n" )
newst = reg.sub ( " ", string1 )
newst1 = newst.split ( " " )

if re.search ( "ERR-2", newst ):
a = re.findall ( "\d\d/\d\d/\d\d\s[012][0-9]:[0-5][0-9]:[0-5][0-9]", newst )
for i in range ( len ( a ) ):
newtime = datetime.datetime.strptime ( a[i], '%m/%d/%y %H:%M:%S' )
if newtime > y and newtime < k:
   print "Install patch1"

if re.search ( "ERR-3", newst ):
a = re.findall ( "\d\d/\d\d/\d\d\s[012][0-9]:[0-5][0-9]:[0-5][0-9]", newst )
for i in range ( len ( a ) ):
newtime = datetime.datetime.strptime ( a[i], '%m/%d/%y %H:%M:%S' )
if newtime > y and newtime < k:
print newtime, y, k
print "Install patch2"

==

output i get :

*Install patch1   - wrong solution
2018-10-22 10:21:23 2018-10-22 10:21:15 2018-10-22 10:21:25
Install patch2   - correct solution *


*It should have only searched between timestamps **2018-10-22 10:21:15
2018-10-22 10:21:25*

*in logC11.txt  what I am doing wrong please adice stuck on this for long.*
Patching tool version 12.2.0.1.0 Production on Mon Oct 22 10:21:15 2018

verify_queryable_inventory returned ERR-1: Latest xml inventory is not loaded 
into table


Prereq check failed, exiting without installing any patches.

Patching tool complete on Mon Oct 22 10:21:25 2018
 LOG file opened at 04/26/18 06:11:52

ERR-2: OS message: No child processes
operation "wait", location "skudmi:prp:6"

 LOG file opened at 10/22/18 09:10:25


ERR-3: patchObjectPossible causes are:"

Trim whitespace same as SQL Loader

 LOG file opened at 10/22/18 10:21:23


ERR-3: patchObjectPossible causes are:"

Trim whitespace same as SQL Loader


 LOG file opened at 10/22/18 10:22:25


ERR-3: patchObjectPossible causes are:"

Trim whitespace same as SQL Loader___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help

2018-10-26 Thread Bob Gailer
On Oct 26, 2018 6:11 AM, "Ben Placella"  wrote:
>
> I need to write code that runs a  cost calculating program with many
> different variables and I honestly don't understand it

Could you be more specific? What exactly don't you understand, or even
better what do you understand?

my code is:

How could you have written so much code without understanding it?

> beefmeals=int(input("Enter number of beef meals: "))
> shitmeals=int(input("Enter number of vegan meals: "))
> party=beefmeals+shitmeals
> print(party)
> if party<=50

Something is missing from that last statement. Can you tell what it is? Do
you know how to find out? Hint use help.

Hint 2 it is also missing from the elif and else statements.

> a=75
> print("Room cost $75")
> elif party <=150
> b=150
> print("Room cost $150")
> else
> c=250
> print("Room cost $250")
> roomtax=party*0.065
> print(roomtax)
> print("Beef Meals", beefmeals)
> $beef=(beefmeals*15.95)
> print($beef)
> print("Beef cost", $$beef)
> print("Vegan Meals", shitmeals)
> $shit=(shitmeals*10.95)
> print($shit)
> cost=($beef+$shit)
> grat=cost*0.18)
> print(grat)
> GT=(grat+$beef+$shit+(a,b,c))

There is a convention in Python that and all uppercase name is a constant.
This is not a requirement.

> print(GT)
>
> This is what the output is supposed to be:

I don't see any output here. Alan''s responses may help you figure that out.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help

2018-10-26 Thread Alan Gauld via Tutor
On 25/10/2018 23:14, Ben Placella wrote:

Please always post code in plain text not HTML or Rich text.
Otherwise we lose all the formatting which is important in Python.

> beefmeals=int(input("Enter number of beef meals: "))
> shitmeals=int(input("Enter number of vegan meals: "))
> party=beefmeals+shitmeals
> print(party)
> if party<=50

Python control statements are terminated by a colon(:)

> $beef=(beefmeals*15.95)

$ signs in front of variable names are an error in Python


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help (shits killing me)

2018-10-26 Thread Steven D'Aprano
On Thu, Oct 25, 2018 at 06:13:31PM -0400, Ben Placella wrote:
> So I have to make a fibonacci sequence, and I'm not sure what is wrong with
> my code
[...]

> attached is a photo of what the output SHOULD look like

No it isn't. For security (anti-spam, anti-virus) reasons, this mailing 
list deletes non-text attachments.

Code is text. Unless you edit your code with Photoshop, don't take 
screenshots or photos of the code. COPY AND PASTE the code, and any 
expected results, or error messages, as TEXT.

Text can be copied, edited, and pasted into the interpreter and run.

Photos of text can't be edited, or run in the interpeter. Screen-readers 
can't read them, making them invisible to the blind or visually 
impaired. Photos of text are useless for programming.

When you run your code, what error do you get? COPY AND PASTE the entire 
traceback, starting from the line "Traceback: ..." and including the 
error message at the end.


-- 
Steve
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help

2018-10-26 Thread Steven D'Aprano
On Thu, Oct 25, 2018 at 06:14:41PM -0400, Ben Placella wrote:
> I need to write code that runs a  cost calculating program with many
> different variables and I honestly don't understand it, my code is:
> beefmeals=int(input("Enter number of beef meals: "))
> shitmeals=int(input("Enter number of vegan meals: "))

What version of Python are you using?

> party=beefmeals+shitmeals
> print(party)
> if party<=50
> a=75

You have lost the indentation, making your code invalid.

Also, you are probably getting a SyntaxError when you try to run your 
code. As always, please COPY AND PASTE (don't retype it from memory, or 
take a photo) the entire traceback, starting from the line 
"Traceback..." and ending with the error message.


> print("Room cost $75")
> elif party <=150
> b=150
> print("Room cost $150")
> else
> c=250
> print("Room cost $250")

That's two more syntax errors.


> $beef=(beefmeals*15.95)

Dollar signs aren't used for Python variables.


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help (shits killing me)

2018-10-26 Thread Alan Gauld via Tutor
Plain text is preferred for code since otherwise the mail
system removes all indentation making the code hard to understand.

On 25/10/2018 23:13, Ben Placella wrote:
> So I have to make a fibonacci sequence, and I'm not sure what is wrong with
> my code
> #This program illustrates the fibonacci sequence
> nterms=int(input("Please enter how many terms you would like to know: "))
> n1 = 1
> n2 = 1
> count = 0
> if nterms <= 0:
> print("Please enter a positive integer")
> elif nterms == 1:
> print("Fibonacci sequence upto",nterms,":")
> print(n1)
> else:
> print("Fibonacci sequence upto",nterms,":")
> while count < nterms:
> print(n1,end=' , ')
> nth = n1 + n

I suspect that n should be n2?

> n1 = n2
> n2 = nth

BTW in Python you can do that set of assignments more
concisely as

n1,n2 = n2, n1+n2

with no temporary variable required.

> count += 1

And rather than using a while loop and manually
maintaining a count you could just use a for loop:

for count in range(nterms):

It's slightly more reliable and a lot more "pythonic".

> attached is a photo of what the output SHOULD look like

This is a text only list so images or other binary files
are stripped off by the server. Please, in future,
cut n' paste any output into the mail body.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Help (shits killing me)

2018-10-26 Thread Andrew Van Valkenburg
nth = n1 + n

I don't see where n is defined anywhere.  Should be n2?

On Fri, Oct 26, 2018 at 6:09 AM Ben Placella 
wrote:

> So I have to make a fibonacci sequence, and I'm not sure what is wrong with
> my code
> #This program illustrates the fibonacci sequence
> nterms=int(input("Please enter how many terms you would like to know: "))
> n1 = 1
> n2 = 1
> count = 0
> if nterms <= 0:
> print("Please enter a positive integer")
> elif nterms == 1:
> print("Fibonacci sequence upto",nterms,":")
> print(n1)
> else:
> print("Fibonacci sequence upto",nterms,":")
> while count < nterms:
> print(n1,end=' , ')
> nth = n1 + n
> n1 = n2
> n2 = nth
> count += 1
>
> attached is a photo of what the output SHOULD look like
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Python Help

2018-10-26 Thread Ben Placella
I need to write code that runs a  cost calculating program with many
different variables and I honestly don't understand it, my code is:
beefmeals=int(input("Enter number of beef meals: "))
shitmeals=int(input("Enter number of vegan meals: "))
party=beefmeals+shitmeals
print(party)
if party<=50
a=75
print("Room cost $75")
elif party <=150
b=150
print("Room cost $150")
else
c=250
print("Room cost $250")
roomtax=party*0.065
print(roomtax)
print("Beef Meals", beefmeals)
$beef=(beefmeals*15.95)
print($beef)
print("Beef cost", $$beef)
print("Vegan Meals", shitmeals)
$shit=(shitmeals*10.95)
print($shit)
cost=($beef+$shit)
grat=cost*0.18)
print(grat)
GT=(grat+$beef+$shit+(a,b,c))
print(GT)

This is what the output is supposed to be:
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Python Help (shits killing me)

2018-10-26 Thread Ben Placella
So I have to make a fibonacci sequence, and I'm not sure what is wrong with
my code
#This program illustrates the fibonacci sequence
nterms=int(input("Please enter how many terms you would like to know: "))
n1 = 1
n2 = 1
count = 0
if nterms <= 0:
print("Please enter a positive integer")
elif nterms == 1:
print("Fibonacci sequence upto",nterms,":")
print(n1)
else:
print("Fibonacci sequence upto",nterms,":")
while count < nterms:
print(n1,end=' , ')
nth = n1 + n
n1 = n2
n2 = nth
count += 1

attached is a photo of what the output SHOULD look like
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor