Shopping List program This is a shopping list program made in Python 3 and it will send the list by email. I am not very experienced but I consider this program as a starting point to what I will do next.

import smtplib

from email.message import EmailMessage

from getpass import getpass

name = str(input("Name: "))
email = str(input("Email: "))
password = str(getpass("Password: "))
recipient = str(input("Recipient's email: "))

while True:
    try:
        productsnm = int(input(f"Hi, {name}!\nHow many products do you want to add to the shopping list? " ))
    except ValueError:
        print ("Please input a number.")
    else:
        break

products = []
quantities = []

for x in range(int(productsnm)):

    product = str(input("Input the product name: "))

    while True:
        try:
            quantity = int(input("Input the product quantity: "))
        except ValueError:
            print ("Please input a number.")
        else:
            break

    products.append(product)
    quantities.append(quantity)

print ("\nThese products have been added to the shopping list:")

for x, y in zip(products, quantities):
    print (f'{x} x {y}')

gmail_user = email 
gmail_password = password

msg = EmailMessage()
msg['Subject'] = "Shopping List"
msg['From'] = gmail_user
msg['To'] = [recipient]
message = ""
for i in range(max(len(products), len(quantities))):
    message = message + str(products[i]) + " x " + str(quantities[i]) + "\n"
msg.set_content(message)

try:
    s = smtplib.SMTP_SSL('smtp.gmail.com', 465)
    s.ehlo()
    s.login(gmail_user, gmail_password)
    s.send_message(msg)
    s.quit()

    print ("\nThe email has been sent.")

except:  
    print ("\nAn error occurred.")

print ("\nHave a nice day!")

exit()
Welcome to Code Review. While your script works as is, it is a good practice to setup and split parts of code into functions, and place the entry point inside the if __name__ wall.



You have an extra conversion to int for productsnm (which could be better named product_count).



Since each product is associated with its own quantity, say hello to a namedtuple:

from collections import namedtuple
Product = namedtuple('Product', ['name', 'quantity'])
# inside the for-loop:
    products.append(Product(name=product_name, quantity=quantity))


You wont need the string manipulation, or the loop. Just printing out the products list should give you something like

[Product(name='n0', quantity=0), Product(name='n1', quantity=1), Product(name='n2', quantity=32)]


Each element of the list now has name and quantity as its property as well.



You can have multiple functions as follows:


gather_products_list which returns a list of N products.
generate_email_body to process the products provided to the function and generating the raw email body.
send_email which accepts the aforementioned raw body, and sends it via the provider of choice.
get_integer which repeatedly asks the user to input an integer value. This function could accept an optional prompt message as well as an error message!