From townerobert1 at gmail.com Sun Apr 7 21:06:47 2024 From: townerobert1 at gmail.com (Robert Towne) Date: Sun, 7 Apr 2024 20:06:47 -0500 Subject: [Tutor] stuck Message-ID: Im unable to figure out what I am doing wrong def convert_distance(miles): km = miles * 1.6 result = "{:.1f} miles equals {:.1f} km".format(miles,km) return result print(convert_distance(12)) # Should be: 12 miles equals 19.2 km print(convert_distance(5.5)) # Should be: 5.5 miles equals 8.8 km print(convert_distance(11)) # Should be: 11 miles equals 17.6 km Not quite. Check that you're using the format method with the placeholder curly brackets and correct decimal place indication. From k.d.jantzen at mailbox.org Mon Apr 8 07:45:47 2024 From: k.d.jantzen at mailbox.org (Klaus Jantzen) Date: Mon, 8 Apr 2024 13:45:47 +0200 Subject: [Tutor] stuck In-Reply-To: References: Message-ID: <67315007-78f4-46ee-907c-e55fdb619453@mailbox.org> On 4/8/24 03:06, Robert Towne wrote: > Im unable to figure out what I am doing wrong > > def convert_distance(miles): > km = miles * 1.6 > result = "{:.1f} miles equals {:.1f} km".format(miles,km) > return result > > > print(convert_distance(12)) # Should be: 12 miles equals 19.2 km > print(convert_distance(5.5)) # Should be: 5.5 miles equals 8.8 km > print(convert_distance(11)) # Should be: 11 miles equals 17.6 km > > > > > > Not quite. Check that you're using the format method with the placeholder > curly brackets and correct decimal place indication. > _______________________________________________ > Tutor maillist -Tutor at python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor Write the result line as follows def convert_distance(miles): ????? km = miles * 1.6 ????? result = f"{miles:.1f} miles equals {km:.1f} km" ????? return result Have'nt used 'format' "for ages". -- K.D.J. From mats at wichmann.us Mon Apr 8 09:36:23 2024 From: mats at wichmann.us (Mats Wichmann) Date: Mon, 8 Apr 2024 07:36:23 -0600 Subject: [Tutor] stuck In-Reply-To: References: Message-ID: <8f5496b6-05a4-406b-bbb6-99f617e00ce4@wichmann.us> On 4/7/24 19:06, Robert Towne wrote: > Im unable to figure out what I am doing wrong > > def convert_distance(miles): > km = miles * 1.6 > result = "{:.1f} miles equals {:.1f} km".format(miles,km) > return result > > > print(convert_distance(12)) # Should be: 12 miles equals 19.2 km > print(convert_distance(5.5)) # Should be: 5.5 miles equals 8.8 km > print(convert_distance(11)) # Should be: 11 miles equals 17.6 km Your code should work - if you indent it properly. We can't always tell here whether this is your mistake or some mail system trying to be clever about what it thinks your writing should look like. Indentation is part of Python syntax. It's ignored in many other programming languages, but used anyway as an aid to readability. In Python a statement ending in a colon is followed by a statement block (one line or more) that must be indented to tell the interpreter which lines are part of the block. For the block that forms the function definition it's the lines up to the ending "return", so your function needs to look like this: def convert_distance(miles): km = miles * 1.6 result = "{:.1f} miles equals {:.1f} km".format(miles,km) return result And yes, as Klaus says, many people prefer the "f-string" syntax - short for formatted string literals - largely because it puts the interpolated variables right there with their formatting instructions and you don't have to keep looking to the right to match up variables with placeholders in the string. But the format() method of strings is still a valid part of the language. From PythonList at DancesWithMice.info Thu Apr 11 01:40:38 2024 From: PythonList at DancesWithMice.info (dn) Date: Thu, 11 Apr 2024 17:40:38 +1200 Subject: [Tutor] Data Ethics (Virtual) Meeting Message-ID: <0681520a-4be0-49f9-bcb5-9f6cbc76ada7@DancesWithMice.info> Virtual meeting, Wed 17 April, 1800 for 1830 (NZST, ie 0630 UTC) Data Ethics Emma McDonald is the Director of the Interim Centre for Data Ethics and Innovation at Stats NZ (New Zealand Government Department of Statistics) Emma will talk about why Stats NZ is establishing a Centre for Data Ethics and Innovation, and why it needs to be set up as a network that draws on and leverages knowledge and expertise across relevant work programmes and people across agencies. As an initiative, the Centre is there to help agencies develop and maintain secure and trusted data environments. A large part of this is drawing on a diverse network of people who can support the with sharing the importance of data ethics being a critical component of data driven technologies. Will be of-interest to Quants, Data Science, and Machine Learning folk; as well as those of us with wider interest in what should/not happen with personal, public, and corporate data... She will be wanting to hear what folk have to say, and is interested to recruit competent individuals for hui*, consultations, and the like. WebRef: https://data.govt.nz/leadership/the-interim-centre-for-data-ethics-and-innovation/ from which you can access their Work Programme and Guidance developed to-date. Please RSVP at https://www.meetup.com/nzpug-auckland/events/299764076/ * hui is the Te Reo Maori word for meeting or conference (Te Reo is one of New Zealand's official languages) -- Regards =dn From carrfamily at mindspring.com Thu Apr 11 12:00:40 2024 From: carrfamily at mindspring.com (carrfamily at mindspring.com) Date: Thu, 11 Apr 2024 12:00:40 -0400 Subject: [Tutor] Need help making Python 3.12 work with Visual Studio 2022 Message-ID: <004a01da8c29$6750fe80$35f2fb80$@mindspring.com> Dear Python Tutorverse I used Microfocus COBOL with Visual Studio very successfully for twenty years. Now I want to start programming in Python, also under the aegis of Visual Studio. I don't need help with the Python language - syntax, etc. What I do need is to make Python work with Visual Studio. Right now, I can't get anything to work, including a simple-stupid "Hello, world". Just need to get over the starting hump. I would like for you to remotely sign into my PC, using TeamViewer or somesuch, and show me how to make this sucker work. I tried to sign up for Tutor, but don't know if it was successful, because I got a message "reCAPTCHA validation failed: invalid-input-response". Tim Carr Benton House Room 208 2711 Lawrenceville Hwy Decatur GA 30033 678.395.3551 From alan.gauld at yahoo.co.uk Fri Apr 12 02:12:26 2024 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Fri, 12 Apr 2024 07:12:26 +0100 Subject: [Tutor] Need help making Python 3.12 work with Visual Studio 2022 In-Reply-To: <004a01da8c29$6750fe80$35f2fb80$@mindspring.com> References: <004a01da8c29$6750fe80$35f2fb80$@mindspring.com> Message-ID: On 11/04/2024 17:00, carrfamily at mindspring.com wrote: > I tried to sign up for Tutor, but don't know if it was successful, because I > got a message "reCAPTCHA validation failed: invalid-input-response". I checked the membership list and I can't find you there. Please try again. -- Alan G List moderator From carrfamily at mindspring.com Sun Apr 28 11:14:26 2024 From: carrfamily at mindspring.com (carrfamily at mindspring.com) Date: Sun, 28 Apr 2024 11:14:26 -0400 Subject: [Tutor] My first program doesn't seem to do anything -- followup Message-ID: <004e01da997e$c29da010$47d8e030$@mindspring.com> I asked an AI to write a python program that would scroll through a folder of pictures, and to display each .jpg it finds for 15 seconds. I'm working in Visual Studio Code. After finally getting it error-free, I ran it but no window opens. Nothing seems to happen. Please advise. Here's the program. # This is pix.py # Python program that will walk through a folder of .jpg files and display each one for 15 seconds import os import time import tkinter as tk from PIL import Image, ImageTk folder_path = "c:/Users/Tim Carr/Pictures/_Parents" def display_images(folder_path): # Create a Tkinter window window = tk.Tk() window.title("Image Viewer") # Get a list of all .jpg files in the folder image_files = [f for f in os.listdir(folder_path) if f.endswith(".jpg")] # Display each image for 15 seconds for image_file in image_files: image_path = os.path.join(folder_path, image_file) image = Image.open(image_path) photo = ImageTk.PhotoImage(image) # Create a label to display the image label = tk.Label(window, image=photo) label.pack() # Display the image for 15 seconds window.after(15000, label.destroy) window.mainloop() Tim Carr Benton House Room 208 2711 Lawrenceville Hwy Decatur GA 30033 678.395.3551 From cs at cskk.id.au Sun Apr 28 17:08:48 2024 From: cs at cskk.id.au (Cameron Simpson) Date: Mon, 29 Apr 2024 07:08:48 +1000 Subject: [Tutor] My first program doesn't seem to do anything -- followup In-Reply-To: <004e01da997e$c29da010$47d8e030$@mindspring.com> References: <004e01da997e$c29da010$47d8e030$@mindspring.com> Message-ID: On 28Apr2024 11:14, carrfamily at mindspring.com wrote: >in Visual Studio Code. After finally getting it error-free, I ran it >but no >window opens. Nothing seems to happen. Please advise. Here's the program. You define the display_images(folder_path) function but you never call it. So it never runs. From threesomequarks at proton.me Sun Apr 28 19:41:24 2024 From: threesomequarks at proton.me (ThreeBlindQuarks) Date: Sun, 28 Apr 2024 23:41:24 +0000 Subject: [Tutor] My first program doesn't seem to do anything -- followup In-Reply-To: References: <004e01da997e$c29da010$47d8e030$@mindspring.com> Message-ID: Cameron, The program probably worked perfectly based on what was asked for. If you asked how to write a function that does what you want, and forget to mention you also want to DO IT, it will tell you how to make the function and unless you add some thought of your own, it will run it exactly zero times with zero results. I have seen variants of this if someone wants a function that accepts multiple arguments that fine tune what it does, such as specify whether or not the data has a header row, and then they call the function and whatever defaults it uses are not what they want, they complain that I gave them the wrong function. Maybe, but you also have to read the manual page or other instructions and call it appropriately. Sometimes you need to tune it so much, that perhaps a different function might have been a better choice for you. Let us know if it works once you properly invoke it. Cue. Sent with Proton Mail secure email. On Sunday, April 28th, 2024 at 5:08 PM, Cameron Simpson wrote: > On 28Apr2024 11:14, carrfamily at mindspring.com carrfamily at mindspring.com wrote: > > > in Visual Studio Code. After finally getting it error-free, I ran it > > but no > > window opens. Nothing seems to happen. Please advise. Here's the program. > > > You define the display_images(folder_path) function but you never call > it. So it never runs. > _______________________________________________ > Tutor maillist - Tutor at python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor From alan.gauld at yahoo.co.uk Sun Apr 28 19:37:27 2024 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Mon, 29 Apr 2024 00:37:27 +0100 Subject: [Tutor] My first program doesn't seem to do anything -- followup In-Reply-To: <004e01da997e$c29da010$47d8e030$@mindspring.com> References: <004e01da997e$c29da010$47d8e030$@mindspring.com> Message-ID: On 28/04/2024 16:14, carrfamily at mindspring.com wrote: > > I asked an AI to write a python program that would scroll through a folder > of pictures, and to display each .jpg it finds for 15 seconds. You need to remember that ChatGPT and its friends are very good at stitching stuff from the web together in such a way that it looks like it was done by a human. But that's all. They make no promises about the stuff being accurate or correct in any meaningful sense. And as you may have discovered they are extremely poor at debugging. > import os > import time > import tkinter as tk > from PIL import Image, ImageTk > > folder_path = "c:/Users/Tim Carr/Pictures/_Parents" > > def display_images(folder_path): > > # Create a Tkinter window > window = tk.Tk() > window.title("Image Viewer") > > # Get a list of all .jpg files in the folder > image_files = [f for f in os.listdir(folder_path) if f.endswith(".jpg")] > > # Display each image for 15 seconds > for image_file in image_files: > image_path = os.path.join(folder_path, image_file) > image = Image.open(image_path) > photo = ImageTk.PhotoImage(image) > > # Create a label to display the image > label = tk.Label(window, image=photo) > label.pack() > > # Display the image for 15 seconds > window.after(15000, label.destroy) > > window.mainloop() Here is an almost minimal version that works. I did add a couple of extras for usability and debugging's sake. It's quite a bit different... import os import time import tkinter as tk from PIL import Image, ImageTk # Get a list of all .jpg files in the folder folder_path = "c:/Users/Tim Carr/Pictures/_Parents" image_files = [f for f in os.listdir(folder_path) if f.endswith((".jpg",".jpeg",".JPG",".JPEG"))] index = 0 def show_image(interval=3000): global index, thePhoto, thePicture thePicture.destroy() del(thePhoto) # Display next image for 3 seconds if index < len(image_files): file_name = image_files[index] image_path = os.path.join(folder_path, file_name) caption['text'] = image_path # create and display a new image newImage = Image.open(image_path) thePhoto = ImageTk.PhotoImage(newImage) thePicture = tk.Label(window, image = thePhoto, width=newImage.width) window['width'] = 500 thePicture.pack() # get ready for the next update event window.after(interval, lambda t=interval: show_image(t)) index += 1 else: # we're finished window.quit() # Create a Tkinter window window = tk.Tk() window.title("Image Viewer") caption = tk.Label(window, text=image_files[-1].lower()) caption.pack() theImage = Image.open(os.path.join(folder_path,image_files[-1])) thePhoto = ImageTk.PhotoImage(theImage) thePicture = tk.Label(window, image = thePhoto) thePicture.pack() show_image() window.mainloop() -- 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 From alan.gauld at yahoo.co.uk Sun Apr 28 20:51:04 2024 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Mon, 29 Apr 2024 01:51:04 +0100 Subject: [Tutor] My first program doesn't seem to do anything -- followup In-Reply-To: References: <004e01da997e$c29da010$47d8e030$@mindspring.com> Message-ID: On 29/04/2024 00:37, Alan Gauld via Tutor wrote: > Here is an almost minimal version that works. I did add a couple of > extras for usability and debugging's sake. Oops sorry, That was an earlier debugging version. Here is the finished version: ################ import os import time import tkinter as tk from PIL import Image, ImageTk # Get a list of all .jpg files in the folder folder_path = "c:/Users/Tim Carr/Pictures/_Parents" image_files = [f for f in os.listdir(folder_path) if f.endswith((".jpg",".jpeg",".JPG",".JPEG"))] index = 0 thePhoto = thePicture = None def show_image(interval=3000): global index, thePhoto, thePicture index += 1 thePicture.destroy() del(thePhoto) # Display next image for 3 seconds if index < len(image_files): file_name = image_files[index] image_path = os.path.join(folder_path, file_name) caption['text'] = file_name # create and display a new image newImage = Image.open(image_path) thePhoto = ImageTk.PhotoImage(newImage) thePicture = tk.Label(window, image = thePhoto, width=newImage.width) window['width'] = 500 thePicture.pack() # get ready for the next update event window.after(interval, lambda t=interval: show_image(t)) else: # we're finished window.quit() # Create a Tkinter window window = tk.Tk() window.title("Image Viewer") caption = tk.Label(window, text=image_files[0]) caption.pack() # show the first image theImage = Image.open(os.path.join(folder_path,image_files[0])) thePhoto = ImageTk.PhotoImage(theImage) thePicture = tk.Label(window, image = thePhoto) thePicture.pack() #start the slide show show_image() window.mainloop() -- 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 From alan.gauld at yahoo.co.uk Sun Apr 28 20:56:09 2024 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Mon, 29 Apr 2024 01:56:09 +0100 Subject: [Tutor] My first program doesn't seem to do anything -- followup In-Reply-To: References: <004e01da997e$c29da010$47d8e030$@mindspring.com> Message-ID: On 29/04/2024 00:37, Alan Gauld via Tutor wrote: > And as you may have discovered they are extremely poor at debugging. As am I, but it is late.... ... > > show_image() > window.mainloop() Should be: window.after(3000,show_image) window.mainloop() My original version fails to display the first image file! -- 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