0% found this document useful (0 votes)
9 views5 pages

Computer Assignment2

Uploaded by

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

Computer Assignment2

Uploaded by

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

Computer Assignment

Name: Muhammad Tayyab

Roll No: 2024-TE-10

Input:

# Input from the user

Number = int(input(“Enter a number: “))

# Check if the number is prime

If number <= 1:

Print(f”{number} is not a prime number.”)

Else:

I=2

Is_prime = True

While I * I <= number: # Check divisors up to the square root of the number

If number % I == 0:

Is_prime = False

Break

I += 1

If is_prime:

Print(f”{number} is a prime number.”)

Else:

Print(f”{number} is not a prime number.”)

Output:
Enter a number: 19

19 is a prime number.

Input:

# Input from the user

Number = int(input(“Enter a number: “))

# Check if the number is prime

If number <= 1:

Print(f”{number} is not a prime number.”)

Else:

I=2

Is_prime = True

While I * I <= number: # Check divisors up to the square root of the number

If number % I == 0:

Is_prime = False

Break

I += 1

If is_prime:

Print(f”{number} is a prime number.”)

Else:

Print(f”{number} is not a prime number.”)

Output:
Enter a number: 30

30 is not a prime number.

Input:

# Input from the user

Number = int(input(“Enter the number for the multiplication table: “))

# Initialize counter

I=1

# While loop for printing the multiplication table

Print(f”Multiplication Table of {number}:”)

While I <= 10:

Print(f”{number} x {i} = {number * i}”)

I += 1

Output:

Enter the number for the multiplication table: 7

Multiplication Table of 7:

7x1=7

7 x 2 = 14

7 x 3 = 21

7 x 4 = 28

7 x 5 = 35

7 x 6 = 42
7 x 7 = 49

7 x 8 = 56

7 x 9 = 63

7 x 10 = 70

Input:

# Input from the user

Number = int(input(“Enter the number for the multiplication table: “))

# Initialize counter

I=1

# While loop for printing the multiplication table

Print(f”Multiplication Table of {number}:”)

While I <= 10:

Print(f”{number} x {i} = {number * i}”)

I += 1

Output:

Enter the number for the multiplication table: 13

Multiplication Table of 13:

13 x 1 = 13

13 x 2 = 26

13 x 3 = 39

13 x 4 = 52

13 x 5 = 65

13 x 6 = 78
13 x 7 = 91

13 x 8 = 104

13 x 9 = 117

13 x 10 = 130

Input:

# Initialize counter

I=1

# While loop for calculating and printing squares

Print(“Squares of the first 10 numbers:”)

While I <= 10:

Print(f”Square of {i} = {i**2}”)

I += 1

Output:

Squares of the first 10 numbers:

Square of 1 = 1

Square of 2 = 4

Square of 3 = 9

Square of 4 = 16

Square of 5 = 25

Square of 6 = 36

Square of 7 = 49

Square of 8 = 64

Square of 9 = 81

Square of 10 = 100

You might also like