0% found this document useful (0 votes)
11 views2 pages

Program 1

The document describes three Python programs that perform different numerical operations based on user input. Program 1 checks if a number is even or odd, Program 2 calculates the square of an even number or the cube of an odd number, and Program 3 checks if one number is divisible by another. Each program includes a variable data type table and a step-by-step algorithm.
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)
11 views2 pages

Program 1

The document describes three Python programs that perform different numerical operations based on user input. Program 1 checks if a number is even or odd, Program 2 calculates the square of an even number or the cube of an odd number, and Program 3 checks if one number is divisible by another. Each program includes a variable data type table and a step-by-step algorithm.
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

PROGRAM 1

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

if number % 2 == 0:
#this is to check wheteher a number is divisible by 0 or not
print("The number is even.")
#if it is divisible by 2 then it will print the number as even
else:
#if it is not divisible by 2 then it will print the number as odd
print("The number is odd.")

VDT:
variable datatype purpose
number Int or integer Stores the number entered by
the user.

Algorithm:
1. Input a number from the user.
2. Check if the number is divisible by 2 without any remainder.
3. If yes, print "The number is even", otherwise print "The number is odd".
Output:
 For example, if the user inputs 7, the output will be "The number is odd."
 This program effectively determines whether a given number is even or odd
and provides the corresponding message.

PROGRAM 2
number = int(input("Enter a number: "))

if number % 2 == 0:
print("Square of", number, "is", number**2)
else:
print("Cube of", number, "is", number**3)
VDT:
variable datatype purpose
number Int or integer Stores the number entered by
the user.

Algorithm:
1. Input a number from the user.
2. Check if the number is divisible by 2 without any remainder.
3. If yes, print the square of the number, otherwise print the cube of the
number.

Output:
 For instance, if the user inputs 5, the output will be "Cube of 5 is 125."
 This program provides the square of an even number and the cube of an odd
number, based on user input.

PROGRAM 3
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))

if num2 == 0:
print("Cannot divide by zero.")
elif num1 % num2 == 0:
print(num1, "is divisible by", num2)
else:
print(num1, "is not divisible by", num2)

VDT:

variable datatype purpose


num1 Int or integer Stores the number entered by
the user.
num2 Int or integer Stores the number entered by
the user.

You might also like