0% found this document useful (0 votes)
2 views

Basic Python Programs

The document contains basic Python programs demonstrating fundamental concepts such as swapping two numbers, checking if a number is odd or even, determining if a number is positive or negative, and printing grades based on total marks. Each program includes user input and conditional statements to perform the required tasks. These examples serve as introductory exercises for beginners learning Python programming.

Uploaded by

binduann
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Basic Python Programs

The document contains basic Python programs demonstrating fundamental concepts such as swapping two numbers, checking if a number is odd or even, determining if a number is positive or negative, and printing grades based on total marks. Each program includes user input and conditional statements to perform the required tasks. These examples serve as introductory exercises for beginners learning Python programming.

Uploaded by

binduann
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Basic Python Programs

1. Swap Two Numbers


# Swapping two numbers using a temporary variable
a = int(input("Enter first number (a): "))
b = int(input("Enter second number (b): "))

# Swapping
temp = a
a=b
b = temp

print("After swapping:")
print("a =", a)
print("b =", b)

2. Check Whether a Number is Odd or Even


num = int(input("Enter a number: "))

if num % 2 == 0:
print("The number is Even.")
else:
print("The number is Odd.")

3. Check Whether a Number is Positive or Negative


num = float(input("Enter a number: "))

if num > 0:
print("The number is Positive.")
elif num < 0:
print("The number is Negative.")
else:
print("The number is Zero.")
4. Print Grade Based on Total Marks
marks = float(input("Enter total marks (out of 100): "))

if marks >= 90:


print("Grade: A+")
elif marks >= 80:
print("Grade: A")
elif marks >= 70:
print("Grade: B")
elif marks >= 60:
print("Grade: C")
elif marks >= 50:
print("Grade: D")
else:
print("Grade: F (Fail)")

You might also like