0% found this document useful (0 votes)
4 views

Python Practice Set 1

The document contains a set of Python programming exercises designed to practice various concepts, including function creation, mathematical operations, conditionals, and number manipulation. Each question provides a specific task such as adding numbers, calculating square roots, identifying prime numbers, and determining the nature of numbers. The exercises aim to enhance programming skills through practical application of Python syntax and logic.
Copyright
© © All Rights Reserved
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% found this document useful (0 votes)
4 views

Python Practice Set 1

The document contains a set of Python programming exercises designed to practice various concepts, including function creation, mathematical operations, conditionals, and number manipulation. Each question provides a specific task such as adding numbers, calculating square roots, identifying prime numbers, and determining the nature of numbers. The exercises aim to enhance programming skills through practical application of Python syntax and logic.
Copyright
© © All Rights Reserved
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 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.

Q3.Write a program that prints all prime numbers between 0 to 50.

Q4.How 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.

Q7.Write a program for sum of digits.the digits are 76543 and the output should be 25.

Q8.Write a program for reversing the given number 5436 and the output should be 6345.

Q9.Write a program to check if a given number 371 is an Armstrong number?

Q10.Write a program the given year is 1996, a leap year.

Data Science Masters

You might also like