python


Adding program in Python

# Prompt the user to enter the first number

num1 = int(input("Enter the first number: "))


# Prompt the user to enter the second number

num2 = int(input("Enter the second number: "))


# Add the two numbers

sum_result = num1 + num2


# Display the sum

print(f"The sum of {num1} and {num2} is: {sum_result}")




Marklist


m1=int(input("Enter the marks 1:"))
m2=int(input("Enter the mark 2:"))
m3=int(input("Enter the mark 3:"))
m4=int(input("Enter the mark 4:"))
m5=int(input("Enter the mark 5:"))
total=m1+m2+m3+m4+m5
per=total/5
print("Total Marks:",total)
print("Percentage Marks:",per)


Billing App

Android App pydroid 3


import tkinter as tk
from tkinter import messagebox

def calculate_total():
    try:
        # Get values from the entry boxes
        name = entry_name.get()
        qty = float(entry_qty.get())
        price = float(entry_price.get())
        
        # Calculate
        total = qty * price
        
        # Update the result label
        result_label.config(text=f"Total: {total:.2f}")
        
    except ValueError:
        # Show error if text is entered instead of numbers
        messagebox.showerror("Input Error", "Please enter valid numbers for Quantity and Price.")

# --- GUI Setup ---
root = tk.Tk()
root.title("Billing App")
root.geometry("400x500") # Set window size

# 1. Item Name
lbl_name = tk.Label(root, text="Item Name:", font=("Arial", 12))
lbl_name.pack(pady=5)
entry_name = tk.Entry(root, font=("Arial", 12))
entry_name.pack(pady=5)

# 2. Quantity
lbl_qty = tk.Label(root, text="Quantity:", font=("Arial", 12))
lbl_qty.pack(pady=5)
entry_qty = tk.Entry(root, font=("Arial", 12))
entry_qty.pack(pady=5)

# 3. Unit Price
lbl_price = tk.Label(root, text="Unit Price:", font=("Arial", 12))
lbl_price.pack(pady=5)
entry_price = tk.Entry(root, font=("Arial", 12))
entry_price.pack(pady=5)

# 4. Calculate Button
btn_calc = tk.Button(root, text="Calculate Total", font=("Arial", 14, "bold"), 
                     bg="green", fg="white", command=calculate_total)
btn_calc.pack(pady=20)

# 5. Result Display
result_label = tk.Label(root, text="Total: 0.00", font=("Arial", 18, "bold"), fg="blue")
result_label.pack(pady=10)

# Start the app
root.mainloop()





Billing App (ബില്ലിംഗ് ആപ്ലിക്കേഷൻ) നിർമ്മിക്കാനുള്ള പൈത്തൺ കോഡാണ്. ഇതിനായി പൈത്തണിലെ Tkinter എന്ന ലൈബ്രറിയാണ് ഉപയോഗിച്ചിരിക്കുന്നത്.

​ഈ പ്രോഗ്രാം എങ്ങനെയാണ് പ്രവർത്തിക്കുന്നത് എന്ന് താഴെ ഘട്ടം ഘട്ടമായി വിശദീകരിക്കാം:

​1. ലൈബ്രറികൾ ഇംപോർട്ട് ചെയ്യുന്നു (Importing Libraries)

import tkinter as tk
from tkinter import messagebox

  • tkinter: വിൻഡോകൾ, ബട്ടണുകൾ, ടെക്സ്റ്റ് ബോക്സുകൾ എന്നിവയടങ്ങിയ GUI (Graphical User Interface) നിർമ്മിക്കാൻ ഇത് ഉപയോഗിക്കുന്നു.
  • messagebox: ഉപഭോക്താവ് തെറ്റായ വിവരങ്ങൾ നൽകിയാൽ (ഉദാഹരണത്തിന് നമ്പറിന് പകരം അക്ഷരങ്ങൾ) ഒരു മുന്നറിയിപ്പ് (Alert) കാണിക്കാൻ ഇത് സഹായിക്കുന്നു.

​2. കണക്കുകൂട്ടൽ ഫംഗ്ഷൻ (Calculation Logic)

​def calculate_total(): എന്ന ഫംഗ്ഷനിലാണ് പ്രധാനപ്പെട്ട കാര്യങ്ങൾ നടക്കുന്നത്.

Total=Quantity*price

\text{Total} = \text{Quantity} \times \text{Price}


റിസൾട്ട് കാണിക്കുന്നു: ലഭിച്ച ഉത്തരം result_label എന്ന ലേബലിലൂടെ സ്ക്രീനിൽ കാണിക്കുന്നു.

Error Handling (try-except): അളവോ വിലയോ നൽകുന്ന സ്ഥലത്ത് അക്ഷരങ്ങൾ നൽകിയാൽ പ്രോഗ്രാം ക്രാഷ് ആകാതിരിക്കാൻ try...except ഉപയോഗിച്ചിരിക്കുന്നു. തെറ്റായ ഇൻപുട്ട് വന്നാൽ "Please enter valid numbers" എന്നൊരു മെസ്സേജ് ബോക്സ് വരും.

3. വിൻഡോ ഡിസൈൻ (GUI Setup)

​ഇവിടെയാണ് ആപ്ലിക്കേഷൻ്റെ രൂപം തീരുമാനിക്കുന്നത്.

  • root = tk.Tk(): പ്രധാന വിൻഡോ നിർമ്മിക്കുന്നു.
  • root.geometry("400x500"): വിൻഡോയുടെ വലിപ്പം തീരുമാനിക്കുന്നു.
  • Labels & Entries:
    • ​Label: "Item Name", "Quantity" എന്നിങ്ങനെ സ്ക്രീനിൽ എഴുതി കാണിക്കാൻ.
    • ​Entry: ഉപഭോക്താവിന് വിവരങ്ങൾ ടൈപ്പ് ചെയ്യാനുള്ള ബോക്സുകൾ.
    • ​.pack(): ഇവയെല്ലാം ഒന്നിനു താഴെ ഒന്നായി സ്ക്രീനിൽ അടുക്കിവെക്കാൻ ഈ കമാൻഡ് ഉപയോഗിക്കുന്നു.

​4. ബട്ടൺ (Button)

btn_calc = tk.Button(..., command=calculate_total)


  • ​"Calculate Total" എന്ന ബട്ടൺ ക്ലിക്ക് ചെയ്യുമ്പോൾ command=calculate_total പ്രവർത്തിക്കുന്നു. അതായത് മുകളിൽ എഴുതിയ ഫംഗ്ഷൻ (കണക്കുകൂട്ടൽ) നടക്കുന്നു.

​5. പ്രോഗ്രാം റൺ ചെയ്യുന്നു

  • ​ഈ വരിയാണ് വിൻഡോ ക്ലോസ് ചെയ്യുന്നത് വരെ സ്ക്രീനിൽ നിലനിർത്തുന്നത്.

​ചുരുക്കത്തിൽ:

​ഈ പ്രോഗ്രാം റൺ ചെയ്യുമ്പോൾ ഒരു വിൻഡോ തുറന്നുവരും. അവിടെ സാധനത്തിന്റെ പേര്, എണ്ണം, വില എന്നിവ നൽകി "Calculate" ബട്ടൺ അമർത്തിയാൽ ആകെ തുക (Total) കണക്കാക്കി താഴെ കാണിക്കും.












Python in computer

Python Quickstart

Python is an interpreted programming language, this means that as a developer you write Python (.py) files in a text editor and then put those files into the python interpreter to be executed.

Let's write our first Python file, called hello.py, which can be done in any text editor:

hello.py:

print("Hello, World!")

Simple as that. Save your file. Open your command line, navigate to the directory where you saved your file, and run:

C:\Users\Your Name>python hello.py

The output should be:

Hello, World!


Popular posts from this blog