Skip to content

Raj702135/Assignment2_python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

2 Commits
ย 
ย 
ย 
ย 

Repository files navigation

Task-1 Odd or Even Number Checker This is a simple Python program that checks whether a given integer is odd or even. It's a beginner-friendly script that demonstrates the use of basic input, conditionals, and the modulo operator in Python.

๐Ÿ“‹ How It Works The user is prompted to enter an integer.

The program checks if the number is divisible by 2 using the modulo (%) operator.

It prints whether the number is even or odd.

๐Ÿงพ Sample Output bash Copy Edit Enter an integer: 7 7 is an odd number. bash Copy Edit Enter an integer: 12 12 is an even number. ๐Ÿง  Concepts Used input() function

Type casting (int)

Conditional statements (if-else)

Modulo operator (%)

๐Ÿš€ How to Run Make sure you have Python installed (preferably Python 3).

Clone this repo or copy the code into a .py file.

Open your terminal and run:

bash Copy Edit python filename.py Replace filename.py with the name of your Python file.

๐Ÿค Contributing Feel free to fork this repo and play around with the logic, maybe extend it to handle floats or validate input!

TASK 2โž• Sum of First 50 Positive Integers This is a simple Python script that calculates the sum of the first 50 positive integers (i.e., numbers from 1 to 50). It's a great beginner exercise for practicing loops and basic arithmetic operations.

๐Ÿ’ก What It Does The program:

Initializes a variable total_sum to 0.

Uses a for loop to iterate from 1 to 50.

Adds each number to total_sum.

Prints the final result.

๐Ÿงพ Output Example bash Copy Edit The sum of numbers from 1 to 50 is: 1275 ๐Ÿง  Concepts Covered for loop

range() function

Variables and arithmetic operations

print() formatting

๐Ÿš€ How to Run the Code Make sure you have Python installed.

Clone this repo or copy the code into a file like sum_first_50.py.

Open your terminal and run

bash Copy Edit python sum_first_50.py

summary These two Python scripts are simple beginner-level programs. The first checks whether a given integer is odd or even using the modulo operator, while the second calculates the sum of the first 50 positive integers using a loop. Both tasks help in understanding basic concepts like loops, conditionals, user input, and arithmetic operations in Python.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published