Basic Python Programming (313011) Practical No.5 Write a simple Python program to demonstrate use of control loops: i) while ii) do while
Control loops are essential for solving iterative problems by automating repetitive tasks and processing data collections efficiently. They are crucial in implementing algorithms like sorting and searching and handling dynamic input gracefully. In concurrent processing, loops manage multiple tasks simultaneously, enhancing performance and scalability in software applications.
Practical related questions
1. Write a program to convert a binary number (input as a string) to its decimal equivalent using looping constructs.
Answer:
2. Implement a program to convert a decimal number (input as an integer) to its binary equivalent using looping constructs.
Answer:
3. Implement a program to count the number of ones in a binary number (input as a string) using looping constructs.
Answer:
4. Implement a program to calculate the output voltage of a voltage divider circuit using given resistor values and an input voltage. Use looping constructs to iterate through different resistor combinations and calculate the output voltage.
Answer:
Exercise:
1. Write a Python program to print all even numbers between 1 to 100 using while loop.
Answer:
number = 2
while number <= 100:
print(number)
number += 2
2. Write a Python program to find the sum and reverse of n-digit numbers using for loop.
Answer:
3. Write a Python program to print Fibonacci series on any number entered by the user.
Answer:
4. Write a Python program to calculate factorial of a number.
Answer:
5. Write a Python to print the LCM and GCD of two non-negative integer numbers.
Answer:
6. Write a Python program which will print all the Armstrong numbers between 1 to 500.
Answer:
7. Write a Python program that takes a number and checks whether it is a palindrome or not.
Answer: