The document contains three Python programming tasks: checking if a number is prime, finding the largest and smallest of three numbers, and displaying a pattern of asterisks. Each task includes a code snippet that demonstrates the solution. The solutions utilize basic programming concepts such as loops, conditionals, and input handling.
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 ratings0% found this document useful (0 votes)
12 views
Computer_programming_1
The document contains three Python programming tasks: checking if a number is prime, finding the largest and smallest of three numbers, and displaying a pattern of asterisks. Each task includes a code snippet that demonstrates the solution. The solutions utilize basic programming concepts such as loops, conditionals, and input handling.
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/ 2
Python Programming
a. Write a program for Input a number and
check if the number is a prime or not. Ans- # Input a number n = int(input("Enter a number: "))
# Assume the number is prime until proven otherwise
is_prime = True
if n > 1: # Check for factors for i in range(2, n): if (n % i) == 0: is_prime = False break else: is_prime = False
# Print the result
if is_prime: print(f"{n} is a prime number.") else: print(f"{n} is not a prime number.")
b. Write a program for Input three numbers
and display the largest / smallest number. Ans- # Take three numbers from user num1 = float(input("Enter first number: ")) num2 = float(input("Enter second number: ")) num3 = float(input("Enter third number: "))
# Calculate the largest number
largest = max(num1, num2, num3) # Calculate the smallest number smallest = min(num1, num2, num3)
# Print the results
print("The largest number is", largest) print("The smallest number is", smallest)
c. Write a program to display the following
patter using loop. * ** *** **** ***** Ans- # Number of rows rows = 5