Skip to content

DharambirAgrawal/Python_Primer_Chapter1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Getting Started with the Repository

To get started with this repository, follow these steps:

  1. Clone the repository to your local machine using the command:

    git clone https://github.com/DharambirAgrawal/Python_Primer_Chapter1
    
  2. Navigate to the repository directory:

    cd Python_Primer_Chapter1
    

About the Repository

This repository contains exercises and solutions for learning Python programming. It is organized into chapters, with each chapter focusing on specific concepts and techniques.

The README file provides an overview of the exercises included in Chapter 1: Python Primer. Each exercise is described in detail, including the required functions and their expected behavior.

Completing these exercises will enhance your understanding of Python and its capabilities. Feel free to explore other chapters in the repository to further expand your Python knowledge.

Good luck with your Python learning journey!

Chapter 1: Python Primer Exercises

Introduction

Welcome to the README file for the Python Primer exercises! This file provides a summary of the exercises included in Chapter 1 of the Python Primer.

Exercise Descriptions

Exercise 1: is_multiple(n, m)

This exercise requires you to write a short program called is_multiple(n, m) that determines whether n is a multiple of m. The function should return True if n is a multiple of m, and False otherwise.

Exercise 2: is_even(k)

In this exercise, you need to implement a Python function called is_even(k) that checks whether an integer k is even. The function should return True if k is even, and False otherwise. However, you are not allowed to use the multiplication, modulo, or division operators.

Exercise 3: minmax(data)

For this exercise, you are required to write a program function called minmax(data) that takes a sequence of numbers and returns the smallest and largest numbers in the form of a tuple. You should not use any built-in functions for this task.

Exercise 4: sqr_sum(n)

In this exercise, you need to write a Python function that takes a positive integer n and returns the sum of the squares of all the positive integers smaller than n.

Exercise 5: sqr_sum_comprehension(n)

This exercise builds upon Exercise 4 and requires you to compute the sum of the squares using Python's comprehension syntax and the built-in sum function.

Exercise 6: sqr_sum_odd(n)

For this exercise, you need to write a Python function that takes a positive integer n and returns the sum of the squares of all the odd positive integers smaller than n.

Exercise 7: sqr_sum_odd_comprehension(n)

Similar to Exercise 5, this exercise asks you to compute the sum of the squares of odd positive integers using Python's comprehension syntax and the built-in sum function.

Exercise 8: Equivalent Index for Negative Indices

In this exercise, you need to determine the equivalent positive index for a given negative index in a string. You should provide the formula to calculate the equivalent positive index.

Exercise 9: Range Constructor Parameters

For this exercise, you need to write the parameters that should be sent to the range constructor to produce a range with the values 50, 60, 70, 80.

Exercise 10: Range Constructor Parameters

Similar to Exercise 9, this exercise asks you to write the parameters that should be sent to the range constructor to produce a range with the values 8, 6, 4, 2, 0, -2, -4, -6, -8.

Exercise 11: List Comprehension

In this exercise, you need to demonstrate how to use Python's list comprehension syntax to produce the list [1, 2, 4, 8, 16, 32, 64, 128, 256].

Exercise 12: Implementing choice() Function

For the final exercise, you are required to implement your own version of the choice() function using only the randrange() function from Python's random module.

Conclusion

These exercises cover various concepts and techniques in Python programming. Completing these exercises will enhance your understanding of Python and its capabilities. Good luck with your Python learning journey!

Good luck with your Python learning journey!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published