0% found this document useful (0 votes)
3 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)
3 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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy