Lab 2
Lab 2
Computer Engineering
01CE1705 – Programming with Python– Lab Manual
PRACTICAL-2
guess = number / 2
while True:
new_guess = (guess + number / guess) / 2
if abs(guess - new_guess) < epsilon:
return new_guess
guess = new_guess
# User input for both the number to find a square root and the error
torelence level.
number = float(input("Enter a number(not negative number): "))
epsilon = float(input("Enter the tolerance level (epsilon): "))
Output:
1
FACULTY OF TECHNOLOGY
Computer Engineering
01CE1705 – Programming with Python– Lab Manual
Source Code:
def check_even(number):
if number % 2 == 0:
return True
else:
return False
# Example usage:
num = int(input("Enter any number: "))
if check_even(num):
print(num, "is an even number.")
else:
print(num, "is an odd number.")
Output:
2
FACULTY OF TECHNOLOGY
Computer Engineering
01CE1705 – Programming with Python– Lab Manual
Source Code:
number = int(input("Enter a number: "))
while number >= 0:
print(number)
number -= 1
Output:
AIM: d) Write a program that uses for loop to print all the
odd numbers in the range input by user.
Source Code:
start = int(input("Enter the starting number: "))
end = int(input("Enter the ending number: "))
3
FACULTY OF TECHNOLOGY
Computer Engineering
01CE1705 – Programming with Python– Lab Manual
Output: