Python Practice
Set 1
Q1. Write a Python program that defines a function called "add_numbers" that takes two arguments (i.e.,
numbers) and returns their sum. Within the function, add the two numbers together and return the result
using the return statement. Call the function with the values 5 and 6, and print out the returned result.
This will result in the addition of 5 and 6, with the output of the program being the sum of these two
numbers.
Q2. Write a Python program that calculates the square root of a given number using a built-in function.
Specifically, the program should take an integer or float input from the user, calculate its square root
using the 'sqrt()' function from the 'math' module, and print out the result to the user. As an example,
calculate the square root of the number 625 using this program, which should output the value of 25.
[Link] a program that prints all prime numbers between 0 to 50.
[Link] can we swap the values of three variables (let's say a, b, and c) without using a fourth variable?
For example, if we have a=5, b=8, and c=9, how can we obtain a=9, b=5, and c=8? The challenge is to
perform this operation without using an additional variable to store any of the values during the
swapping process.
Q5. Can you write a program that determines the nature of a given number (in this case, 87) as being
positive, negative, or zero? The program should be designed to take the number as input and perform the
necessary calculations to determine if the number is positive (i.e., greater than zero), negative (i.e., less
than zero), or zero (i.e., equal to zero). The output of the program should indicate which of these three
categories the given number falls into.
Q6. How can you create a program that determines whether a given number (in this case, 98) is even or
odd? The program should be designed to take the number as input and perform the necessary
calculations to determine whether it is divisible by two. If the number is divisible by two without leaving a
remainder, it is an even number, and if there is a remainder, it is an odd number. The output of the
program should indicate whether the given number is even or odd.
[Link] a program for sum of [Link] digits are 76543 and the output should be 25.
[Link] a program for reversing the given number 5436 and the output should be 6345.
[Link] a program to check if a given number 371 is an Armstrong number?
[Link] a program the given year is 1996, a leap year.
Data Science Masters