Skip to content

vipinsahu2003/Basic-python-code

Repository files navigation

Python Programming Fundamentals

This repository includes beginner Python scripts focusing on basic concepts, control structures, functions, modules, file handling, and data structures.

Basic Concepts

  • Mathematical Operations:
    Prompts the user for two numbers, calculates and displays their sum, difference, product, and division. Demonstrates arithmetic operators and simple input/output.

  • Personalized Greeting:
    Takes first and last name input, combines them, and prints a greeting message to the user.

How to Run These Programs

  1. Make sure Python is installed.
  2. Open terminal/command prompt.
  3. Navigate to the script directory.
  4. Run each program using:
    python task1_basic_math.py
    python task2_greeting.py
    

Control Structures

  • Even/Odd Number Checker:
    Asks for an integer input and uses an if-else statement to check if the number is even or odd.

  • Sum of Numbers (1 to 50):
    Calculates and prints the sum of all integers from 1 to 50 using a for loop.

How to Run These Programs

  1. Confirm Python is installed.
  2. Open terminal/command prompt and go to the project directory.
  3. Run the scripts using:
    python check_even_odd.py
    python sum_1_to_50.py
    

Functions & Modules

  • Factorial Calculator:
    Defines a function to calculate the factorial of a number using recursion or loops.

  • Math Module Calculations:
    Uses Python's built-in math module to compute square root, natural logarithm, and sine of a user-entered number.

How to Run These Programs

  1. Ensure Python is installed.
  2. Open terminal/command prompt.
  3. Navigate to the project folder.
  4. Run the scripts with:
    python factorial_function.py
    python math_module_calculations.py
    

Files, Exceptions, and Errors

  • Read File with Error Handling:
    Opens and reads a file named sample.txt. Prints its contents line by line and handles errors if the file does not exist.

  • Write and Append Data to a File:
    Takes user input to write to a file, appends additional data, then reads and displays the complete file contents.

How to Run These Programs

  1. Verify Python is installed on your system.
  2. Open terminal or command prompt and navigate to your project folder.
  3. Execute:
    python read_file.py
    python write_append_file.py
    

Data Structures and Strings

  • Student Marks Lookup:
    Implements a dictionary where student names are keys and their marks are values. The user can input a student's name to retrieve marks, with proper handling for missing entries.

  • List Slicing Demonstration:
    Creates a list of numbers from 1 to 10, extracts the first five elements, reverses them, and displays both the extracted and reversed lists.

How to Run These Programs

  1. Make sure Python is installed.
  2. Open terminal/command prompt and go to the project folder.
  3. Run the scripts using:
    python student_marks_dictionary.py
    python list_slicing_demo.py
    

Note:
These scripts are designed for interactive, beginner-friendly learning of essential Python programming concepts.

About

Simple Python programs illustrating basic concepts in Python programming.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages