user_input=int(input("Enter your number : "))
output=user_input**0.5print(output)
04. Area of triangle
formula : area = 0.5 * base * height.
Complexity Analysis
Time Complexity: O(1)
Auxiliary Space: O(1)
Solution
base=float(input("Enter the base length of the triangle: "))
height=float(input("Enter the height of the triangle: "))
area=0.5*base*heightprint("The area of the triangle is:", area)
05. Quadratic Equation
Complexity Analysis
Time Complexity: O(1)
Auxiliary Space: O(1)
Solution
06. Swap Variable
input : a = 5
b = 6
output : a = 6
b = 5
Complexity Analysis
Time Complexity: O(1)
Auxiliary Space: O(1)
input : 2024
output : Leap Year
Complexity Analysis
Time Complexity: O(1)
Auxiliary Space: O(1)
Solution
year=int(input("Enter your your : "))
ifyear%4==0andyear%100!=0oryear%400==0:
print("Leap Year")
else:
print("Not leap year ")
11. Find the Largest Among Three Numbers
input : a = 5
b = 6
c = 10
output : C is large number
Complexity Analysis
Time Complexity: O(1)
Auxiliary Space: O(1)
Solution
a=int(input("Enter your 1st number : "))
b=int(input("Enter your 2nd number : "))
c=int(input("Enter your 3rd number : "))
ifa>b:
print("A is largest number")
elifb>c:
print("B is largest number ")
elifa<c:
print("C is largest number")
12. Check Prime Number
input : 13
output : Its Prime
Definition :
A prime number can be defined as a natural number greater than 1
whose only factors are 1 and the number itself.
Solution
is_prime=int(input("Enter your number : "))
foriinrange(2, is_prime):
ifis_prime%i==0:
print("Not a prime number ")
breakelse:
print("Its Prime")
13. Prime numbers within an interval
input : 900, 1000
output : Its Prime
Solution
lower=int(input("Enter your lower number : "))
upper=int(input("Enter your upper number : "))
fornuminrange(lower, upper+1):
ifnum>1:
foriinrange(2, num):
if (num%i) ==0:
breakelse:
print(num)
number=int(input("Enter your number : "))
foriinrange(1, 11):
print(number,'x', i, '=', i*number)
# ornum=1whilenum<=10:
print(num,'x', num, '=', num*num)
num=num+1
16. Python Program to Print the Fibonacci sequence
Solution
num = 7
factorial = 1
if num < 0:
print("Sorry, factorial does not exist for negative numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
for i in range(1,num + 1):
factorial = factorial*i
print("The factorial of",num,"is",factorial)