Skip to content

shubhangiwaghchauregithub/Python_assignment_2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Python_assignment_2

Task 1 A number is even if it is perfectly divisible by 2, meaning it leaves a remainder of 0 when divided by 2. It is odd if the remainder is 1.

How the Program Works Input: The program prompts the user to enter an integer using input().

Conversion: Since input() returns text, the input is converted to an integer type with int().

Check Using Modulo Operator % : The program calculates num % 2.

If the result is 0, the number is even.

Otherwise, it is odd.

Conditional Output: Using an if-else statement, the program prints whether the number is "even" or "odd" accordingly.

Task 2 he program calculates the total sum of all integers starting from 1 up to 50.

How the Program Works Initialization: A variable sum is initialized to 0 to store the cumulative total.

Looping: A for loop iterates over the range of numbers from 1 to 50 inclusive (range(1, 51)).

Accumulation: In each iteration, the current number i is added to the sum variable using sum += i.

Output: After the loop completes, the total sum is printed.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages